2024-10-11 17:27:31 +08:00

27 lines
568 B
TypeScript

import { TOKEN_KEY } from '@/enums/cacheEnum';
import { getCache, setCache } from '@/utils/cache';
const authenticationScheme = 'Bearer';
export function getToken() {
return getCache<string>(TOKEN_KEY) || null;
}
export function getAuthorization() {
const token = getToken();
return token ? `${authenticationScheme} ${token}` : null;
}
export function setToken(token: string) {
return setCache(TOKEN_KEY, token);
}
export function removeToken() {
return setCache(TOKEN_KEY, null);
}
// 是否登录
export function isLogin() {
return !!getToken();
}