Ver código fonte

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

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
k4be 2 semanas atrás
pai
commit
2edcff8a58
1 arquivos alterados com 4 adições e 2 exclusões
  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');
     }