|
|
@ -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格式) */ |
|
|
|