fix: Ensure admin panel is functional by linking the station manager role to admin permissions #102
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.
Fix Admin Permissions for Station Managers
Problem
Users with
stationManagerrole in the default organization were unable to access Better Auth Admin plugin endpoints (/admin/*). The Admin plugin checks the globaluser.rolefield (not organization membership) to authorize requests, but organization roles were not being synced to this field.Solution
Implemented automatic synchronization of
user.roleto"admin"when users are promoted tostationManager,admin, orownerroles in the default organization.Changes
shared/authentication/src/auth.definition.tsorganizationHooksto the organization plugin:afterAddMember: Setsuser.role = "admin"when members are added with admin rolesafterUpdateMemberRole: Updatesuser.roleon role changes (grants on promotion, removes on demotion)afterRemoveMember: Removes admin role when members are removed from default organizationDEFAULT_ORG_SLUG)apps/auth/app.tscreateDefaultUser()to setuser.role = "admin"immediately when creating a default user withstationManagerrolesyncAdminRoles()function to ensure consistency for existing users created before hooks were implementedTechnical Details
The Better Auth Admin plugin requires
user.role === "admin"in the database to authorize admin endpoints. Organization roles (stationManager,admin,owner) are stored in themembertable and are separate from the globaluser.rolefield. This change bridges that gap by automatically maintaininguser.rolebased on organization membership in the default organization.Testing
stationManagerusers receive admin role on service startupstationManagerrole receive admin role immediatelyuser.roleaccordingly