Browse Source

Merge remote-tracking branch 'origin/hella_online_20240803' into hella_online_20240803

linshi20240813
gaojs 3 months ago
parent
commit
b4aec7179c
  1. 20
      src/utils/auth.ts

20
src/utils/auth.ts

@ -10,24 +10,32 @@ const RefreshTokenKey = 'REFRESH_TOKEN'
// 获取token // 获取token
export const getAccessToken = () => { export const getAccessToken = () => {
// 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错 // 此处与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 // 刷新token
export const getRefreshToken = () => { export const getRefreshToken = () => {
return wsCache.get(RefreshTokenKey) // return wsCache.get(RefreshTokenKey)
return sessionStorage.getItem(RefreshTokenKey)
} }
// 设置token // 设置token
export const setToken = (token: TokenType) => { export const setToken = (token: TokenType) => {
wsCache.set(RefreshTokenKey, token.refreshToken) // wsCache.set(RefreshTokenKey, token.refreshToken)
wsCache.set(AccessTokenKey, token.accessToken) // wsCache.set(AccessTokenKey, token.accessToken)
sessionStorage.setItem(RefreshTokenKey,token.refreshToken)
sessionStorage.setItem(AccessTokenKey,token.accessToken)
} }
// 删除token // 删除token
export const removeToken = () => { export const removeToken = () => {
wsCache.delete(AccessTokenKey) // wsCache.delete(AccessTokenKey)
wsCache.delete(RefreshTokenKey) // wsCache.delete(RefreshTokenKey)
sessionStorage.removeItem(AccessTokenKey)
sessionStorage.removeItem(RefreshTokenKey)
} }
/** 格式化token(jwt格式) */ /** 格式化token(jwt格式) */

Loading…
Cancel
Save