From d3993fd61528f2e47cb89b8b1e900aabaf7005ed Mon Sep 17 00:00:00 2001 From: wangyufei <2267742828@qq.com> Date: Sat, 10 Aug 2024 17:05:20 +0800 Subject: [PATCH] =?UTF-8?q?SCP=EF=BC=8CWMS=E7=B3=BB=E7=BB=9F=E7=9A=84WEB?= =?UTF-8?q?=E7=AB=AF=E5=8F=96=E6=B6=88token=E4=BF=9D=E6=8C=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=86=8D=E6=89=93=E5=BC=80=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E9=87=8D=E6=96=B0=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/auth.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/utils/auth.ts b/src/utils/auth.ts index 7da49b08b..53cdbd581 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -10,24 +10,32 @@ const RefreshTokenKey = 'REFRESH_TOKEN' // 获取token export const getAccessToken = () => { // 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错 - return wsCache.get(AccessTokenKey) ? wsCache.get(AccessTokenKey) : wsCache.get('ACCESS_TOKEN') + // return wsCache.get(AccessTokenKey) ? wsCache.get(AccessTokenKey) : wsCache.get('ACCESS_TOKEN') + return sessionStorage.getItem(AccessTokenKey) ? sessionStorage.getItem(AccessTokenKey) : sessionStorage.getItem('ACCESS_TOKEN') + } // 刷新token export const getRefreshToken = () => { - return wsCache.get(RefreshTokenKey) + // return wsCache.get(RefreshTokenKey) + return sessionStorage.getItem(RefreshTokenKey) + } // 设置token export const setToken = (token: TokenType) => { - wsCache.set(RefreshTokenKey, token.refreshToken) - wsCache.set(AccessTokenKey, token.accessToken) + // wsCache.set(RefreshTokenKey, token.refreshToken) + // wsCache.set(AccessTokenKey, token.accessToken) + sessionStorage.setItem(RefreshTokenKey,token.refreshToken) + sessionStorage.setItem(AccessTokenKey,token.accessToken) } // 删除token export const removeToken = () => { - wsCache.delete(AccessTokenKey) - wsCache.delete(RefreshTokenKey) + // wsCache.delete(AccessTokenKey) + // wsCache.delete(RefreshTokenKey) + sessionStorage.removeItem(AccessTokenKey) + sessionStorage.removeItem(RefreshTokenKey) } /** 格式化token(jwt格式) */