修复一些问题,个人账号功能完善,注册功能完善,收藏,购物车功能完善,初版基本完成,投入测试
This commit is contained in:
@@ -271,6 +271,19 @@ router.beforeEach((to, _from, next) => {
|
||||
} else if (to.path === '/home' && !token) {
|
||||
next('/')
|
||||
} else {
|
||||
// 对于需要认证的页面,验证token的有效性
|
||||
if (requiresAuth && token) {
|
||||
// 检查userInfo是否存在
|
||||
const userInfo = localStorage.getItem('userInfo')
|
||||
if (!userInfo) {
|
||||
console.log('Token存在但userInfo不存在,清除token并跳转到登录页')
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
next('/')
|
||||
return
|
||||
}
|
||||
}
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user