bug(web): admin page redirects to /chat — role check fails #196
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Navigating to
/adminin the web dashboard immediately redirects to/chatinstead of showing the admin panel. This happens even for users withrole: "admin"in the database.Redirect Chain
Root Cause Analysis
The
AdminRoleGuardcomponent (src/components/admin-role-guard.tsx) reads the role from the BetterAuth session:The
rolefield is defined as anadditionalFieldsproperty inpackages/auth/src/auth.ts:Possible causes:
BetterAuth session does not include
rolein the user object — TheadditionalFieldsconfig may not automatically include the role in the session response. The client-sideuseSession()may return a user object without therolefield, causing theuser?.role !== 'admin'check to always be true.Admin plugin session mismatch — The
admin()plugin is configured withadminRoles: ['admin']but the session user object fromuseSession()might not expose the role the same way the admin plugin expects it.User actually has role
member— The user in the database may not have been promoted to admin. Check theusertable for therolecolumn value.Debugging Steps
await fetch('http://localhost:4000/api/auth/get-session', { credentials: 'include' }).then(r => r.json())— inspect whetheruser.roleis presentSELECT id, email, role FROM "user"— verify the user hasrole = 'admin'additionalFieldsare included in the session response by default or need explicit configurationLocation
apps/web/src/components/admin-role-guard.tsx— role check and redirectapps/web/src/app/page.tsx— root page redirects to/chatpackages/auth/src/auth.ts:59—roleadditional field definitionpackages/auth/src/auth.ts:71— admin plugin configurationSteps to Reproduce
role: 'admin'in the database/admin/chat