feat: 加入白名单
This commit is contained in:
parent
133388467d
commit
4a531c2334
|
@ -17,3 +17,5 @@ export const REDIRECT_ROUTE_NAME = 'Redirect';
|
||||||
|
|
||||||
// 首页路由
|
// 首页路由
|
||||||
export const DEFAULT_ROUTE_NAME = 'Workbench';
|
export const DEFAULT_ROUTE_NAME = 'Workbench';
|
||||||
|
|
||||||
|
export const WHITE_LIST_NAME = WHITE_LIST.map((el) => el.name);
|
||||||
|
|
|
@ -8,7 +8,7 @@ export default function setupUserLoginInfoGuard(router: Router) {
|
||||||
if (isLoginExpires()) {
|
if (isLoginExpires()) {
|
||||||
clearToken();
|
clearToken();
|
||||||
}
|
}
|
||||||
if (to.name !== 'login' && hasToken()) {
|
if (to.name !== 'login' && hasToken(to.name as string)) {
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
// 未登录的都直接跳转至登录页,访问的页面地址缓存到 query 上
|
// 未登录的都直接跳转至登录页,访问的页面地址缓存到 query 上
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { isLogin as isLoginFun } from '@/api/modules/user';
|
import { isLogin as isLoginFun } from '@/api/modules/user';
|
||||||
|
import { WHITE_LIST_NAME } from '@/router/constants';
|
||||||
|
|
||||||
const SESSION_ID = 'sessionId';
|
const SESSION_ID = 'sessionId';
|
||||||
const CSRF_TOKEN = 'csrfToken';
|
const CSRF_TOKEN = 'csrfToken';
|
||||||
|
@ -26,7 +27,10 @@ const clearToken = () => {
|
||||||
localStorage.removeItem(CSRF_TOKEN);
|
localStorage.removeItem(CSRF_TOKEN);
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasToken = () => {
|
const hasToken = (name: string) => {
|
||||||
|
if (WHITE_LIST_NAME.includes(name)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return !!localStorage.getItem(SESSION_ID) && !!localStorage.getItem(CSRF_TOKEN);
|
return !!localStorage.getItem(SESSION_ID) && !!localStorage.getItem(CSRF_TOKEN);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue