feat: 登录会话持久化 + Caddy 反代部署方案

This commit is contained in:
root
2026-10-16 11:27:15 +08:00
parent de3add8881
commit 2660dc6fa9
7 changed files with 79 additions and 34 deletions
+5 -4
View File
@@ -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 {