fix dashboard statistic and login guard warnings
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user