-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Problem Description
Multiple components are checking for a 'SuperAdmin' key in localStorage that does not exist in production and has never been set during the authentication flow. This bug causes incorrect permission checks and feature access issues.
Discovery
This issue was discovered during investigation in PR #7169 by @adityai0 while fixing Organization Settings bugs.
Root Cause Analysis
The Non-Existent Key
The 'SuperAdmin' localStorage key is never set during login:
// LoginPage.tsx - handleLoginSuccess (lines 123-129)
// ❌ 'SuperAdmin' is NEVER set here
setItem('IsLoggedIn', 'TRUE');
setItem('name', user.name);
setItem('email', user.emailAddress);
setItem('role', user.role); // ← Only 'role' is set, not 'SuperAdmin'
setItem('UserImage', sanitizeAvatarURL(user.avatarURL));
// ... NO setItem('SuperAdmin', ...) call!Where It's Used Incorrectly
The 'SuperAdmin' key only exists in test mocks (.spec.tsx files), but production code incorrectly tries to read it:
// ❌ WRONG - This key doesn't exist!
const superAdmin = getItem('SuperAdmin');This means:
- Permission checks always fail
- Features meant for admins are broken
getItem('SuperAdmin')always returnsnullin production
Files Affected
1. src/screens/AdminPortal/EventManagement/EventManagement.tsx
Current buggy code:
const superAdmin = getItem('SuperAdmin');
const userRole = superAdmin ? 'SUPERADMIN' : getItem('role');Issue: Since superAdmin is always null, this logic never grants SUPERADMIN status.
2. src/screens/AdminPortal/Requests/Requests.tsx
Current buggy code:
const rawSuperAdmin = getItem('SuperAdmin');
const isSuperAdmin =
rawSuperAdmin === true ||
rawSuperAdmin === 'true' ||
rawSuperAdmin === 'TRUE';Issue: rawSuperAdmin is always null, so isSuperAdmin is always false.
Note: This file later correctly checks getItem('role') at line 112, showing the correct pattern is already known in the codebase:
// ✅ CORRECT pattern (already used later in the same file!)
const userRole = getItem('role') as string;
const isAdmin = userRole?.toLowerCase() === 'administrator';Correct Implementation Pattern
Option 1: Check role in localStorage (already set during login)
// ✅ CORRECT - Works in production
const userRole = getItem('role') as string;
const isSuperAdmin = userRole === 'administrator' || userRole === 'superuser';Option 2: Defensive with array check
// ✅ CORRECT - Case-insensitive and safe
const userRole = getItem('role') as string;
const isSuperAdmin = Boolean(userRole && ['administrator', 'superuser'].includes(userRole.toLowerCase()));Option 3: Query GraphQL if real-time data needed
// ✅ CORRECT - Use if fresh data from backend is required
const { data } = useQuery(CURRENT_USER);
const isSuperAdmin = data?.currentUser?.appUserProfile?.isSuperAdmin;Acceptance Criteria
- Replace
getItem('SuperAdmin')withgetItem('role')inEventManagement.tsx - Replace
getItem('SuperAdmin')withgetItem('role')inRequests.tsx - Use role values:
'administrator'or'superuser'for admin checks - Update associated test files to remove
SuperAdminmocks and use'role'instead - Verify admin features work correctly after changes
- Add defensive null checks for
userRole - Ensure consistency: use the same pattern across both files
Test Cases to Verify
-
Login as Administrator
- Verify
getItem('role')returns'administrator' - Verify admin-only features are accessible
- Verify
-
Login as Regular User
- Verify
getItem('role')returns'user'or other non-admin role - Verify admin features are correctly hidden/disabled
- Verify
-
Unit Tests
- Update mocks to set
role: 'administrator'instead ofSuperAdmin: true - Verify all test assertions still pass
- Update mocks to set
Additional Context
Related PR
- PR fix(org-settings): resolve multiple failures in Organization Settings screen (invalid GraphQL query, language dropdown error) #7169 (current PR) is fixing the same issue in
DeleteOrg.tsx - This issue tracks the remaining files with the same bug
Evidence from Codebase
- The
'SuperAdmin'key appears only in test mocks (.spec.tsxfiles) - No production code ever calls
setItem('SuperAdmin', ...) - The
'role'field is reliably set during login and is the source of truth for user permissions
Files to Update
Production Files
src/screens/AdminPortal/EventManagement/EventManagement.tsxsrc/screens/AdminPortal/Requests/Requests.tsx
Test Files (update mocks)
src/screens/AdminPortal/EventManagement/EventManagement.spec.tsxsrc/screens/AdminPortal/Requests/Requests.spec.tsx
Effort Estimate
⏱️ Small - Straightforward find-and-replace with test updates
Discovered by: @adityai0 in PR #7169
References:
- PR fix(org-settings): resolve multiple failures in Organization Settings screen (invalid GraphQL query, language dropdown error) #7169 - Organization Settings bug fixes
- PR Merge latest AdminUI Redesign into develop #972 - Original AdminUI Redesign that may have introduced similar issues
Note: @adityai0 - Please self-assign this issue to track the work!
Metadata
Metadata
Assignees
Labels
Type
Projects
Status