Преглед на файлове

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');
     }