feat(auth): 重构认证系统,引入 session 会话管理

- 新增 user_sessions 数据库表及 Alembic 迁移
- 实现 SessionService 会话生命周期管理(创建/刷新/撤销/清理)
- 认证流程改用 refresh token cookie + access token 双令牌模式
- 前端实现自动静默刷新、跨标签页同步及设备指纹
- 用户设置页新增会话管理和密码修改功能
- 管理员用户管理新增强制登出和会话查看
- 密码策略增强,支持强度校验和泄露检测
- OAuth 登录流程适配新会话机制
- 新增完整的单元测试和 API 测试覆盖

Closes #232

Co-authored-by: LewisPen <LewisPen@nyadoo.com>
This commit is contained in:
fawney19
2026-03-17 16:34:09 +08:00
parent d480aa11f3
commit c4bb6b8161
58 changed files with 4654 additions and 508 deletions

View File

@@ -0,0 +1,29 @@
export interface UserSession {
id: string
device_label: string
device_type: string
browser_name?: string | null
browser_version?: string | null
os_name?: string | null
os_version?: string | null
device_model?: string | null
ip_address?: string | null
last_seen_at?: string | null
created_at: string
is_current: boolean
revoked_at?: string | null
revoke_reason?: string | null
}
export function formatSessionMeta(session: UserSession): string {
const parts = [
session.browser_name && session.browser_version
? `${session.browser_name} ${session.browser_version}`
: session.browser_name || null,
session.os_name && session.os_version
? `${session.os_name} ${session.os_version}`
: session.os_name || null,
session.device_model || null,
].filter(Boolean)
return parts.length > 0 ? parts.join(' \u00b7 ') : '\u8bbe\u5907\u4fe1\u606f\u672a\u77e5'
}