Skip to content

Conversation

@bokelley
Copy link
Contributor

Summary

  • Fixed 401 redirect handling in 14 admin HTML files by correcting window.AdminNav.redirectToLogin() to window.AdminSidebar.redirectToLogin()
  • Removed dead code in admin-org-detail.html that referenced AdminNav.user which never existed

Problem

When users accessed admin pages while logged out:

  1. API returned 401
  2. JavaScript tried to call window.AdminNav.redirectToLogin()
  3. AdminNav was undefined (correct object is AdminSidebar)
  4. This threw an error caught by the catch block
  5. Showed "Failed to load admin data" instead of redirecting to login

Test plan

  • Verified admin page loads correctly when authenticated
  • Verified clicking "Try logging in again" link redirects to login page
  • All tests pass

🤖 Generated with Claude Code

bokelley and others added 2 commits January 19, 2026 11:37
When users accessed admin pages while logged out, the API returned 401
but the JavaScript tried to call window.AdminNav.redirectToLogin() which
doesn't exist. The correct object is window.AdminSidebar.

This caused the catch block to show "Failed to load admin data" instead
of properly redirecting to the login page.

Fixed in 14 admin HTML files. Also removed dead code in admin-org-detail
that referenced AdminNav.user which never existed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added a shared fetch wrapper that automatically handles 401 redirects,
so pages don't need to duplicate the 401 check. Usage:

  // Before (repeated in every page):
  const response = await fetch('/api/admin/...');
  if (!response.ok) {
    if (response.status === 401) {
      window.AdminSidebar.redirectToLogin();
      return;
    }
    throw new Error('...');
  }

  // After (401 handled automatically):
  const response = await AdminSidebar.fetch('/api/admin/...');
  if (!response.ok) {
    throw new Error('...');
  }

Updated admin.html as an example. Other pages can be migrated gradually.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bokelley bokelley merged commit 5e7a071 into main Jan 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants