40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { STORAGE_KEYS } from './config'
|
|
|
|
export interface TokenData {
|
|
accessToken: string
|
|
refreshToken: string
|
|
expireTime: number
|
|
}
|
|
|
|
export function getAccessToken(): string {
|
|
return wx.getStorageSync(STORAGE_KEYS.ACCESS_TOKEN) || ''
|
|
}
|
|
|
|
export function getRefreshToken(): string {
|
|
return wx.getStorageSync(STORAGE_KEYS.REFRESH_TOKEN) || ''
|
|
}
|
|
|
|
export function getExpireTime(): number {
|
|
return wx.getStorageSync(STORAGE_KEYS.EXPIRE_TIME) || 0
|
|
}
|
|
|
|
export function setTokens(data: TokenData): void {
|
|
wx.setStorageSync(STORAGE_KEYS.ACCESS_TOKEN, data.accessToken)
|
|
wx.setStorageSync(STORAGE_KEYS.REFRESH_TOKEN, data.refreshToken)
|
|
wx.setStorageSync(STORAGE_KEYS.EXPIRE_TIME, data.expireTime)
|
|
}
|
|
|
|
export function clearTokens(): void {
|
|
wx.removeStorageSync(STORAGE_KEYS.ACCESS_TOKEN)
|
|
wx.removeStorageSync(STORAGE_KEYS.REFRESH_TOKEN)
|
|
wx.removeStorageSync(STORAGE_KEYS.EXPIRE_TIME)
|
|
}
|
|
|
|
export function isLoggedIn(): boolean {
|
|
return !!getAccessToken()
|
|
}
|
|
|
|
export function clearUserInfo(): void {
|
|
wx.removeStorageSync(STORAGE_KEYS.USER_INFO)
|
|
}
|