fix: 修复切换用户后会话列表返回错误用户数据

根因:cookie残留/污染 + localStorage autoRestore 自动恢复旧用户
- 浏览器清cookie不会清localStorage,autoRestore用旧token自动恢复登录
- 前端req()未发Authorization头,完全依赖cookie认证
- 当cookie失效时req.user为空,后端不过滤会话返回所有数据

修复:
- 登录成功后存凭据到sessionStorage,req()自动加Basic auth头
- logout彻底清理:sessionStorage + localStorage + POST /api/logout
- autoRestore失败时清除无效token,成功时续期token
- 退出跳转带logged_out参数,login页兜底清除所有凭据
This commit is contained in:
2026-09-05 16:26:03 +08:00
parent bbacf48dcf
commit d778ab12da
2 changed files with 11 additions and 2 deletions
+2 -1
View File
@@ -3324,7 +3324,8 @@
// 账户
changePassword: changePassword,
logout: async function () {
sessionStorage.removeItem('agent_creds'); // 清凭据,避免下次访问仍走 Basic auth
sessionStorage.removeItem('agent_creds'); // 清 Basic auth 凭据
localStorage.removeItem('agent_token'); // 清 autoRestore token,防止自动恢复旧用户
try { await fetch('/api/logout', { method: 'POST' }); } catch (_) {}
location.href = '/logout';
},