From 0ef88eab883147c0e86721335e26cdddc70a68b2 Mon Sep 17 00:00:00 2001 From: zhongzm Date: Wed, 22 Jan 2025 18:40:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:token=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/guard/route.ts | 6 +++--- src/service/request/index.ts | 4 ++-- src/service/request/shared.ts | 6 +++--- src/store/modules/auth/index.ts | 4 ++-- src/store/modules/auth/shared.ts | 6 +++--- src/typings/storage.d.ts | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/router/guard/route.ts b/src/router/guard/route.ts index 3714f91..e1f9adf 100644 --- a/src/router/guard/route.ts +++ b/src/router/guard/route.ts @@ -30,7 +30,7 @@ export function createRouteGuard(router: Router) { const loginRoute: RouteKey = 'login'; const noAuthorizationRoute: RouteKey = '403'; - const isLogin = Boolean(localStg.get('token')); + const isLogin = Boolean(localStg.get('tokenU')); const needLogin = !to.meta.constant; const routeRoles = to.meta.roles || []; @@ -150,7 +150,7 @@ async function checkRoute(to: RouteLocationNormalized): Promise Object.keys(wanfiRedirectParams).includes(s))) { - localStg.remove('token'); + localStg.remove('tokenU'); sessionStg.remove('wanfiRedirectParams'); reLoadLocationHref(); } diff --git a/src/service/request/index.ts b/src/service/request/index.ts index 01ce2db..654a0fa 100644 --- a/src/service/request/index.ts +++ b/src/service/request/index.ts @@ -25,7 +25,7 @@ export const request = createFlatRequest( const { headers } = config; // set token - const token = localStg.get('token'); + const token = localStg.get('tokenU'); const Authorization = token ? `Bearer ${token}` : null; // set language @@ -144,7 +144,7 @@ export const rawRequest = createRequest( const { headers } = config; // set token - const token = localStg.get('token'); + const token = localStg.get('tokenU'); const Authorization = token ? `Bearer ${token}` : null; // set language diff --git a/src/service/request/shared.ts b/src/service/request/shared.ts index 7b06f92..402991e 100644 --- a/src/service/request/shared.ts +++ b/src/service/request/shared.ts @@ -11,11 +11,11 @@ import { fetchRefreshToken } from '../api/auth'; export async function handleRefreshToken(axiosConfig: AxiosRequestConfig) { const { resetStore } = useAuthStore(); - const refreshToken = localStg.get('refreshToken') || ''; + const refreshToken = localStg.get('refreshTokenU') || ''; const { error, data } = await fetchRefreshToken(refreshToken); if (!error) { - localStg.set('token', data.access_token); - localStg.set('refreshToken', data.refreshToken); + localStg.set('tokenU', data.access_token); + localStg.set('refreshTokenU', data.refreshToken); const config = { ...axiosConfig }; if (config.headers) { diff --git a/src/store/modules/auth/index.ts b/src/store/modules/auth/index.ts index 91192f7..90c036b 100644 --- a/src/store/modules/auth/index.ts +++ b/src/store/modules/auth/index.ts @@ -100,8 +100,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { async function loginByToken(loginToken: Api.Auth.LoginToken) { // 1. stored in the localStorage, the later requests need it in headers - localStg.set('token', loginToken.access_token); - localStg.set('refreshToken', loginToken.refreshToken); + localStg.set('tokenU', loginToken.access_token); + localStg.set('refreshTokenU', loginToken.refreshToken); token.value = loginToken.access_token; const isSuccess = await refreshUserInfo(); diff --git a/src/store/modules/auth/shared.ts b/src/store/modules/auth/shared.ts index 917b208..a8f7d9a 100644 --- a/src/store/modules/auth/shared.ts +++ b/src/store/modules/auth/shared.ts @@ -2,7 +2,7 @@ import { localStg } from '@/utils/storage'; /** Get token */ export function getToken() { - return localStg.get('token') || ''; + return localStg.get('tokenU') || ''; } export const emptyInfo: Api.Auth.UserInfo = { @@ -13,6 +13,6 @@ export const emptyInfo: Api.Auth.UserInfo = { /** Clear auth storage */ export function clearAuthStorage() { - localStg.remove('token'); - localStg.remove('refreshToken'); + localStg.remove('tokenU'); + localStg.remove('refreshTokenU'); } diff --git a/src/typings/storage.d.ts b/src/typings/storage.d.ts index 5f86895..e35823e 100644 --- a/src/typings/storage.d.ts +++ b/src/typings/storage.d.ts @@ -15,9 +15,9 @@ declare namespace StorageType { /** The i18n language */ lang: App.I18n.LangType; /** The token */ - token: string; + tokenU: string; /** The refresh token */ - refreshToken: string; + refreshTokenU: string; /** The user info */ userInfo: Api.Auth.UserInfo; /** The theme color */