|
|
|
@ -9,26 +9,34 @@ const RefreshTokenKey = 'REFRESH_TOKEN' |
|
|
|
|
// 获取token
|
|
|
|
|
export const getAccessToken = () => { |
|
|
|
|
// 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错
|
|
|
|
|
return cache.local.get(AccessTokenKey) |
|
|
|
|
? cache.local.get(AccessTokenKey) |
|
|
|
|
: cache.local.get('ACCESS_TOKEN') |
|
|
|
|
return localStorage.getItem(AccessTokenKey) |
|
|
|
|
? localStorage.getItem(AccessTokenKey) |
|
|
|
|
: localStorage.getItem('ACCESS_TOKEN') |
|
|
|
|
// return cache.local.get(AccessTokenKey)
|
|
|
|
|
// ? cache.local.get(AccessTokenKey)
|
|
|
|
|
// : cache.local.get('ACCESS_TOKEN')
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 刷新token
|
|
|
|
|
export const getRefreshToken = () => { |
|
|
|
|
return cache.local.get(RefreshTokenKey) |
|
|
|
|
return localStorage.getItem(RefreshTokenKey) |
|
|
|
|
// return cache.local.get(RefreshTokenKey)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 设置token
|
|
|
|
|
export const setToken = (token: TokenType) => { |
|
|
|
|
cache.local.set(RefreshTokenKey, token.refreshToken) |
|
|
|
|
cache.local.set(AccessTokenKey, token.accessToken) |
|
|
|
|
localStorage.setItem(AccessTokenKey, token.accessToken) |
|
|
|
|
localStorage.setItem(RefreshTokenKey, token.refreshToken) |
|
|
|
|
// cache.local.set(RefreshTokenKey, token.refreshToken)
|
|
|
|
|
// cache.local.set(AccessTokenKey, token.accessToken)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 删除token
|
|
|
|
|
export const removeToken = () => { |
|
|
|
|
cache.local.delete(AccessTokenKey) |
|
|
|
|
cache.local.delete(RefreshTokenKey) |
|
|
|
|
localStorage.removeItem(AccessTokenKey) |
|
|
|
|
localStorage.removeItem(RefreshTokenKey) |
|
|
|
|
// cache.local.delete(AccessTokenKey)
|
|
|
|
|
// cache.local.delete(RefreshTokenKey)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 格式化token(jwt格式) */ |
|
|
|
|