Installation
1
Add the plugin to your auth config
auth.ts
2
Migrate the database
Run the migration or generate the schema to add the necessary fields.- migrate
- generate
3
Add the client plugin
auth-client.ts
Usage
An admin is any user with theadmin role or whose user ID appears in adminUserIds. All admin operations require an authenticated admin session.
Create a user
List users
Get a user
Update a user
Set a user’s role
Set a user’s password
Ban and unban users
Banning a user prevents sign-in and revokes all existing sessions.Session management
Impersonate a user
Impersonation lets admins create a session acting as a specific user. The session expires after 1 hour by default.By default, admins cannot impersonate other admin users. To allow this, grant the
impersonate-admins permission to a role using custom access control.Remove a user
Permanently deletes a user from the database.Roles and permissions
Default roles
Default permissions
Custom permissions
1
Create an access controller
permissions.ts
2
Define roles with permissions
permissions.ts
3
Check permissions
From the client:Options
auth.ts
Schema
The admin plugin adds the following fields to theuser table:
And adds one field to the
session table: