Add is_admin field to UserResponse schema and update AuthContext to fetch user profile after login, storing and exposing isAdmin boolean. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1.4 KiB
1.4 KiB
title, status, type, priority, created_at, updated_at, parent, blocked_by
| title | status | type | priority | created_at | updated_at | parent | blocked_by | |
|---|---|---|---|---|---|---|---|---|
| Expose admin status to frontend via user API | completed | task | normal | 2026-03-21T10:06:20Z | 2026-03-21T10:18:26Z | nuzlocke-tracker-ce4o |
|
The frontend needs to know if the current user is an admin so it can show/hide the Admin nav link and protect admin routes client-side.
Checklist
- Add
is_adminfield to the user response schema (/api/users/meendpoint) - Update
AuthContextto fetch/api/users/meafter login and storeisAdminin context - Expose
isAdminboolean fromuseAuth()hook - Handle edge case: user exists in Supabase but not yet in local DB (first login creates user row with
is_admin=false)
Files to change
backend/src/app/schemas/user.pyor equivalent — addis_adminto responsebackend/src/app/api/users.py— ensure/mereturnsis_adminfrontend/src/contexts/AuthContext.tsx— fetch and store admin status
Summary of Changes
Added isAdmin field to frontend auth system:
- Backend: Added
is_admin: bool = FalsetoUserResponseschema inbackend/src/app/api/users.py - Frontend: Updated
AuthContextto fetch/api/users/meafter login and exposeisAdminboolean - Edge case handled:
syncUserProfilereturnsfalseif API call fails (new user auto-created withis_admin=falseby backend)