Admin Plugin Configuration
Overview
The Better Auth Admin Plugin provides platform-level administrative capabilities. In the Gremlin monorepo, it is used to manage global user roles (user, admin, superadmin) and perform administrative actions like banning or deleting users.
Configuration
The plugin is enabled during thebetterAuth initialization in the DIContainer.
Location
backend/bun/apps/monolith/src/config/di-container.ts
Implementation
- Platform Roles: Core roles for system-wide permissions.
- Admin APIs: Endpoints for managing users and roles.
- Banning: Ability to suspend user access globally.
Core Features
1. Platform Roles
The plugin adds arole field to the users table.
| Role | Description |
|---|---|
user | Default role for all new signups. Regular platform access. |
admin | Can perform administrative tasks (manage other users). |
superadmin | Highest privilege level. Usually restricted to system owners. |
2. Administrative Endpoints
The Bun backend exposes these endpoints via the Better Auth API:POST /api/auth/admin/set-role: Change a user’s platform role.POST /api/auth/admin/ban-user: Suspend a user.POST /api/auth/admin/unban-user: Lift a suspension.POST /api/auth/admin/delete-user: Permanently remove a user.
3. Middleware Integration
Platform roles are extracted in thejwt plugin and injected into the authentication token:
Usage Example
Promoting a User to Admin
To promote a user, asuperadmin would call:
Security Considerations
- Strict Access: Only users with
superadminrole can escalate other users toadmin. - JWT Invalidation: Banning a user does not immediately invalidate their current JWT. The Go backend handles this by checking the
isActiveclaim during the 5-minute cache TTL window, or by checking the database if the claim is missing.