调整目录

This commit is contained in:
mlogclub
2026-04-24 12:01:30 +08:00
parent 7889ecb0d2
commit a9275c2d4a
209 changed files with 0 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
export type AuthUser = {
id: number
username: string
nickname: string
avatar: string
status: number
roles: string[]
}
export type AuthSession = {
accessToken: string
refreshToken: string
expiresAt?: string
user: AuthUser
permissions: string[]
roles: string[]
}
const SESSION_STORAGE_KEY = "cs-agent.admin.session"
function hasWindow() {
return typeof window !== "undefined"
}
export function readSession(): AuthSession | null {
if (!hasWindow()) {
return null
}
const raw = window.localStorage.getItem(SESSION_STORAGE_KEY)
if (!raw) {
return null
}
try {
return JSON.parse(raw) as AuthSession
} catch {
window.localStorage.removeItem(SESSION_STORAGE_KEY)
return null
}
}
export function writeSession(session: AuthSession) {
if (!hasWindow()) {
return
}
window.localStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(session))
}
export function clearSession() {
if (!hasWindow()) {
return
}
window.localStorage.removeItem(SESSION_STORAGE_KEY)
}