feat: 登录会话持久化 + Caddy 反代部署方案
This commit is contained in:
@@ -31,10 +31,11 @@ export interface Session {
|
||||
username: string
|
||||
}
|
||||
|
||||
// 会话存 sessionStorage:关闭标签页即退出,刷新页面保持登录
|
||||
// 会话持久化到 localStorage:关闭浏览器后仍保持登录,无需每次使用都登录
|
||||
// 安全边界:密码库主密码不随会话保存,每次启动仍需解锁
|
||||
export function getSession(): Session | null {
|
||||
try {
|
||||
const raw = sessionStorage.getItem(SESSION_KEY)
|
||||
const raw = localStorage.getItem(SESSION_KEY)
|
||||
if (!raw) return null
|
||||
const s = JSON.parse(raw)
|
||||
if (s && s.userId && s.username) return s as Session
|
||||
@@ -42,10 +43,10 @@ export function getSession(): Session | null {
|
||||
return null
|
||||
}
|
||||
function setSession(s: Session): void {
|
||||
sessionStorage.setItem(SESSION_KEY, JSON.stringify(s))
|
||||
localStorage.setItem(SESSION_KEY, JSON.stringify(s))
|
||||
}
|
||||
function clearSession(): void {
|
||||
sessionStorage.removeItem(SESSION_KEY)
|
||||
localStorage.removeItem(SESSION_KEY)
|
||||
}
|
||||
|
||||
export function openUserDatabase(userId: string): void {
|
||||
|
||||
Reference in New Issue
Block a user