fix: Corpus Agent token not persisted to localStorage, refresh loses memory
This commit is contained in:
parent
d7753f034f
commit
0d03df2f17
@ -222,7 +222,7 @@ let chatHistory = [];
|
|||||||
document.getElementById('user-badge').textContent = username;
|
document.getElementById('user-badge').textContent = username;
|
||||||
fetch('/api/auth/quick-login?username=' + encodeURIComponent(u))
|
fetch('/api/auth/quick-login?username=' + encodeURIComponent(u))
|
||||||
.then(function(r) { return r.json(); })
|
.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() {});
|
.catch(function() {});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ function doLogout() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-login
|
// 自动恢复:页面刷新后从localStorage恢复session
|
||||||
if (token) {
|
if (token) {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
@ -242,7 +242,6 @@ if (token) {
|
|||||||
const d = await r.json();
|
const d = await r.json();
|
||||||
if (d.ok) {
|
if (d.ok) {
|
||||||
username = d.username;
|
username = d.username;
|
||||||
|
|
||||||
document.getElementById('app').style.display = 'flex';
|
document.getElementById('app').style.display = 'flex';
|
||||||
document.getElementById('user-badge').textContent = username;
|
document.getElementById('user-badge').textContent = username;
|
||||||
updateApiPanel();
|
updateApiPanel();
|
||||||
@ -250,6 +249,9 @@ if (token) {
|
|||||||
loadSamples();
|
loadSamples();
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem('corpus_token');
|
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'); }
|
} catch(e) { localStorage.removeItem('corpus_token'); }
|
||||||
})();
|
})();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user