Fix 鉴权失败后的空页面
This commit is contained in:
10
main.go
10
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 => {
|
||||
|
||||
Reference in New Issue
Block a user