Fix 鉴权失败后的空页面

This commit is contained in:
XOF
2025-12-07 21:03:05 +08:00
parent ef33749927
commit 06f8cada47

10
main.go
View File

@@ -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 => {