mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-26 04:39:53 +01:00
fix: 修复登录状态下还能访问白名单路由问题
This commit is contained in:
parent
4aa63baf75
commit
dc581d7185
1 changed files with 12 additions and 6 deletions
|
|
@ -197,16 +197,22 @@ const anonRouteNames = new Set(['login', 'Register', 'RetrievePassword', 'welcom
|
||||||
|
|
||||||
// 路由守卫
|
// 路由守卫
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
if (anonRouteNames.has(to.name)) {
|
const token = localStorage.getItem('token');
|
||||||
next()
|
const isAnonRoute = anonRouteNames.has(to.name);
|
||||||
|
|
||||||
|
if (isAnonRoute && token) {
|
||||||
|
next({ name: 'home', replace: true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 非白名单路由必须登录
|
|
||||||
const token = localStorage.getItem('token')
|
if (!isAnonRoute && !token) {
|
||||||
if (!token) {
|
next({
|
||||||
next({ name: 'login' })
|
name: 'login',
|
||||||
|
replace: true
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue