From 06f8cada47c68e8492fb25f2079d516b4692a6ca Mon Sep 17 00:00:00 2001 From: XOF Date: Sun, 7 Dec 2025 21:03:05 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20=E9=89=B4=E6=9D=83=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E7=A9=BA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 77534e3..41b9cb3 100644 --- a/main.go +++ b/main.go @@ -265,10 +265,16 @@ func handleIndex(w http.ResponseWriter, r *http.Request) { const token = localStorage.getItem('token') || prompt('请输入访问令牌:'); if(token) localStorage.setItem('token', token); const headers = {'Authorization': 'Bearer ' + token}; - function loadTasks() { fetch('/api/tasks', {headers}) - .then(r => r.json()) + .then(r => { + if (!r.ok) { + localStorage.removeItem('token'); + alert('认证失败,请刷新页面重新输入'); + throw new Error('Unauthorized'); + } + return r.json(); + }) .then(tasks => { const tbody = document.querySelector('#taskTable tbody'); tbody.innerHTML = tasks.map(t => {