fix: Correct AdminNav to AdminSidebar for 401 redirect handling#810
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
window.AdminNav.redirectToLogin()towindow.AdminSidebar.redirectToLogin()AdminNav.userwhich never existedProblem
When users accessed admin pages while logged out:
window.AdminNav.redirectToLogin()AdminNavwas undefined (correct object isAdminSidebar)Test plan
🤖 Generated with Claude Code