fix dashboard statistic and login guard warnings

This commit is contained in:
david
2026-07-29 16:45:17 +08:00
parent 94f6492d6e
commit a6fbb8da21
2 changed files with 15 additions and 8 deletions

View File

@@ -5,9 +5,14 @@ import { useUserStore } from '@/store';
import { isLogin } from '@/utils/auth';
export default function setupUserLoginInfoGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
router.beforeEach(async (to, _from, next) => {
NProgress.start();
const userStore = useUserStore();
// 登录页不需要校验旧令牌,避免后端未启动或令牌过期时重复请求用户资料。
if (to.name === 'login') {
next();
return;
}
if (isLogin()) {
if (userStore.role) {
next();
@@ -15,7 +20,7 @@ export default function setupUserLoginInfoGuard(router: Router) {
try {
await userStore.info();
next();
} catch (error) {
} catch {
await userStore.logout();
next({
name: 'login',
@@ -27,10 +32,6 @@ export default function setupUserLoginInfoGuard(router: Router) {
}
}
} else {
if (to.name === 'login') {
next();
return;
}
next({
name: 'login',
query: {