mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-09 18:59:50 +08:00
feat(auth): 重构认证系统,引入 session 会话管理
- 新增 user_sessions 数据库表及 Alembic 迁移 - 实现 SessionService 会话生命周期管理(创建/刷新/撤销/清理) - 认证流程改用 refresh token cookie + access token 双令牌模式 - 前端实现自动静默刷新、跨标签页同步及设备指纹 - 用户设置页新增会话管理和密码修改功能 - 管理员用户管理新增强制登出和会话查看 - 密码策略增强,支持强度校验和泄露检测 - OAuth 登录流程适配新会话机制 - 新增完整的单元测试和 API 测试覆盖 Closes #232 Co-authored-by: LewisPen <[email protected]>
This commit is contained in:
@@ -70,7 +70,13 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
async function logout() {
|
||||
user.value = null
|
||||
token.value = null
|
||||
authApi.logout()
|
||||
await authApi.logout()
|
||||
}
|
||||
|
||||
function applyExternalLogout() {
|
||||
user.value = null
|
||||
token.value = null
|
||||
error.value = null
|
||||
}
|
||||
|
||||
async function fetchCurrentUser() {
|
||||
@@ -80,6 +86,10 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
return userInfo
|
||||
} catch (err: unknown) {
|
||||
log.error('Failed to fetch user info', err)
|
||||
syncToken()
|
||||
if (!token.value) {
|
||||
user.value = null
|
||||
}
|
||||
// 根据用户要求,不管什么错误都不清除状态
|
||||
// 保持登录状态,除非用户手动退出
|
||||
log.info('Keeping session despite error, as per user requirement')
|
||||
@@ -106,6 +116,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
isAdmin,
|
||||
login,
|
||||
logout,
|
||||
applyExternalLogout,
|
||||
fetchCurrentUser,
|
||||
checkAuth,
|
||||
syncToken
|
||||
|
||||
Reference in New Issue
Block a user