fix(auth): 权限异常 清除localstorage

feature/artists
mackt 7 months ago
parent 7def728351
commit cc9c96108d

@ -4,7 +4,6 @@
*/
import { produce } from 'immer';
// import { setCookie } from 'nookies';
import { create } from 'zustand';
import { devtools, persist, createJSONStorage } from 'zustand/middleware';

@ -11,20 +11,24 @@ export const checkAuthOffline: () => boolean = () => {
};
export const getAuthorization = async () => {
const { token, expires } = await parseCookies();
if (!token) return;
if (token && !isExpToken(parseInt(expires ?? 0))) {
return token;
} else if (token) {
logout();
const { token } = await parseCookies();
return token || '';
// if (!token) return '';
// const exp = parseInt(expires ?? 0);
// console.log(111, !isExpToken(exp));
// if (!isExpToken(exp)) {
// return token;
// } else {
// logout();
// return '';
// return tokenRefresh();
// token 过期了重新登录请求然后给请求头设置好token
// 获取token的方法等也可以根据authType的不同进行自定义设置
// const res = await getToken("账号密码等");
// setSession("local", tokenKey, res?.data);
// authorization = res?.data;
}
// }
};
export function setAccessToken({ token, expires }: { token: string; expires: string }) {

@ -67,7 +67,12 @@ export const checkResponseState = async (response: FetchResponse<any>) => {
*/
if ([400, 401, 10000].includes(code)) {
// 判断是否有 token
if (checkAuthOffline()) logout();
if (checkAuthOffline()) {
logout();
window.location.reload();
} else {
localStorage.clear();
}
// 打开登录框
openLogin();

Loading…
Cancel
Save