mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-10 02:40:23 +08:00
add frontend/vben from vben-admin-thin
This commit is contained in:
26
frontend/vben/src/utils/auth/index.ts
Normal file
26
frontend/vben/src/utils/auth/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Persistent, BasicKeys } from '/@/utils/cache/persistent'
|
||||
import { CacheTypeEnum } from '/@/enums/cacheEnum'
|
||||
import projectSetting from '/@/settings/projectSetting'
|
||||
import { TOKEN_KEY } from '/@/enums/cacheEnum'
|
||||
|
||||
const { permissionCacheType } = projectSetting
|
||||
const isLocal = permissionCacheType === CacheTypeEnum.LOCAL
|
||||
|
||||
export function getToken() {
|
||||
return getAuthCache(TOKEN_KEY)
|
||||
}
|
||||
|
||||
export function getAuthCache<T>(key: BasicKeys) {
|
||||
const fn = isLocal ? Persistent.getLocal : Persistent.getSession
|
||||
return fn(key) as T
|
||||
}
|
||||
|
||||
export function setAuthCache(key: BasicKeys, value) {
|
||||
const fn = isLocal ? Persistent.setLocal : Persistent.setSession
|
||||
return fn(key, value, true)
|
||||
}
|
||||
|
||||
export function clearAuthCache(immediate = true) {
|
||||
const fn = isLocal ? Persistent.clearLocal : Persistent.clearSession
|
||||
return fn(immediate)
|
||||
}
|
||||
Reference in New Issue
Block a user