瀏覽代碼

Fix 401 handler: only clear token and reload if token exists

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
k4be 2 周之前
父節點
當前提交
2edcff8a58
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      gpx-vis-frontend/js/api.js

+ 4 - 2
gpx-vis-frontend/js/api.js

@@ -16,8 +16,10 @@ const API = (() => {
 
     const res = await fetch(url, opts);
     if (res.status === 401) {
-      localStorage.removeItem('token');
-      window.location.reload();
+      if (getToken()) {
+        localStorage.removeItem('token');
+        window.location.reload();
+      }
       throw new Error('Unauthorized');
     }