rnilkyway commited on
Commit
92b517e
Β·
1 Parent(s): b483bc2

fix(admin): prevent infinite reload loop on 401

Browse files
Files changed (1) hide show
  1. app/templates/dashboard.html +12 -1
app/templates/dashboard.html CHANGED
@@ -393,7 +393,18 @@
393
  // ── API Helpers ─────────────────────────────────────────────
394
  async function api(path, opts = {}) {
395
  const r = await fetch(path, { ...opts, headers: { 'Authorization': 'Bearer ' + masterKey, 'Content-Type': 'application/json', ...(opts.headers || {}) } });
396
- if (r.status === 401) { sessionStorage.removeItem('apiarium_master_key'); location.reload(); return null; }
 
 
 
 
 
 
 
 
 
 
 
397
  return r;
398
  }
399
 
 
393
  // ── API Helpers ─────────────────────────────────────────────
394
  async function api(path, opts = {}) {
395
  const r = await fetch(path, { ...opts, headers: { 'Authorization': 'Bearer ' + masterKey, 'Content-Type': 'application/json', ...(opts.headers || {}) } });
396
+ if (r.status === 401) {
397
+ console.error('Auth failed for', path, await r.text());
398
+ if (path === '/admin/keys') {
399
+ sessionStorage.removeItem('apiarium_master_key');
400
+ showAuth();
401
+ authError.textContent = 'Invalid master key';
402
+ authError.classList.remove('hidden');
403
+ } else {
404
+ console.warn('Endpoint returned 401:', path);
405
+ }
406
+ return null;
407
+ }
408
  return r;
409
  }
410