diff --git a/app/server/public/index.html b/app/server/public/index.html
index 00a8939..75c6c7c 100644
--- a/app/server/public/index.html
+++ b/app/server/public/index.html
@@ -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';
},
diff --git a/app/server/public/login.html b/app/server/public/login.html
index 0f0e19f..46503ce 100644
--- a/app/server/public/login.html
+++ b/app/server/public/login.html
@@ -53,6 +53,7 @@
async function autoRestore() {
if (new URLSearchParams(location.search).has('logged_out')) {
localStorage.removeItem(TOKEN_KEY); // 显式登出:不恢复,并清掉旧 token
+ sessionStorage.removeItem('agent_creds');
return;
}
const t = localStorage.getItem(TOKEN_KEY);
@@ -61,9 +62,16 @@
form.style.visibility = 'hidden'; // 恢复期间先藏表单,避免闪现
try {
const res = await fetch('/api/login_restore', { method: 'POST', headers: { Authorization: 'Bearer ' + t } });
- if (res.ok) { location.replace('/'); return; }
+ if (res.ok) {
+ const j = await res.json().catch(() => ({}));
+ if (j && j.token) localStorage.setItem(TOKEN_KEY, j.token); // 续期 token
+ location.replace('/');
+ return;
+ }
} catch (_) { /* 网络错误交给表单正常登录 */ }
+ // 恢复失败(401等):清掉无效 token,显示登录表单
localStorage.removeItem(TOKEN_KEY);
+ sessionStorage.removeItem('agent_creds');
form.style.visibility = '';
}
async function doLogin(e) {