mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00: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) => {
|
||||
if (anonRouteNames.has(to.name)) {
|
||||
next()
|
||||
const token = localStorage.getItem('token');
|
||||
const isAnonRoute = anonRouteNames.has(to.name);
|
||||
|
||||
if (isAnonRoute && token) {
|
||||
next({ name: 'home', replace: true })
|
||||
return
|
||||
}
|
||||
// 非白名单路由必须登录
|
||||
const token = localStorage.getItem('token')
|
||||
if (!token) {
|
||||
next({ name: 'login' })
|
||||
|
||||
if (!isAnonRoute && !token) {
|
||||
next({
|
||||
name: 'login',
|
||||
replace: true
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
next()
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue