fix(web): 会话失效时强制清本地 token,避免卡死无法进入登录页

坏 JWT 会导致 logout 接口失败,原先 removeToken 执行不到,且 getInfo 失败后跳到 / 形成死循环。

Confidence: high
Scope-risk: narrow
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
“wuzhen”andCursor committed 2026-10-26 15:50:34 +08:00
1 parent 937cbb6bbd
commit eeae0af978
2 files changed
+14 -8

No files matched your search

+3 -2
View File
@@ -37,6 +37,7 @@ router.beforeEach(async (to, from, next) => {
to.meta.title && useSettingsStore().setTitle(to.meta.title as string);
/* has token*/
if (to.path === '/login') {
// 已有 token 时先进首页;若会话已失效,下面 getInfo 失败会清 token 并回登录页
next({ path: '/' });
NProgress.done();
} else if (isWhiteList(to.path)) {
@@ -47,9 +48,9 @@ router.beforeEach(async (to, from, next) => {
// 判断当前用户是否已拉取完user_info信息
const [err] = await tos(useUserStore().getInfo());
if (err) {
isRelogin.show = false;
await useUserStore().logout();
// ElMessage.error(err.message || '获取用户信息失败');
next({ path: '/' });
next(`/login?redirect=${encodeURIComponent(to.fullPath || '/')}`);
} else {
isRelogin.show = false;
const accessRoutes = await usePermissionStore().generateRoutes();