fix: Corpus Agent token not persisted to localStorage, refresh loses memory

This commit is contained in:
root 2026-05-22 16:50:42 +08:00
parent d7753f034f
commit 0d03df2f17

View File

@ -222,7 +222,7 @@ let chatHistory = [];
document.getElementById('user-badge').textContent = username;
fetch('/api/auth/quick-login?username=' + encodeURIComponent(u))
.then(function(r) { return r.json(); })
.then(function(d) { if (d.ok) { token = d.token; document.getElementById('app').style.display = 'flex'; updateApiPanel(); loadStats(); loadSamples(); addSystemMsg('✅ 欢迎回来,有什么语料需要整理的?'); } })
.then(function(d) { if (d.ok) { token = d.token; localStorage.setItem('corpus_token', token); document.getElementById('app').style.display = 'flex'; updateApiPanel(); loadStats(); loadSamples(); addSystemMsg('✅ 欢迎回来,有什么语料需要整理的?'); } })
.catch(function() {});
})();
@ -234,7 +234,7 @@ function doLogout() {
}
// Auto-login
// 自动恢复页面刷新后从localStorage恢复session
if (token) {
(async () => {
try {
@ -242,7 +242,6 @@ if (token) {
const d = await r.json();
if (d.ok) {
username = d.username;
document.getElementById('app').style.display = 'flex';
document.getElementById('user-badge').textContent = username;
updateApiPanel();
@ -250,6 +249,9 @@ if (token) {
loadSamples();
} else {
localStorage.removeItem('corpus_token');
// fallback: re-login via homepage
var u = localStorage.getItem('current_user');
if (u) { window.location.href = '/corpus/'; }
}
} catch(e) { localStorage.removeItem('corpus_token'); }
})();