Skip to main content
The Admin plugin provides a set of administrative functions for managing users in your application. Administrators can create users, manage roles, ban or unban users, impersonate users, revoke sessions, and more.

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.
3

Add the client plugin

auth-client.ts

Usage

An admin is any user with the admin 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

Pass roles to the plugin

auth.ts
auth-client.ts

Check permissions

From the client:
From the server:
Synchronous role check (no network call):

Options

auth.ts

Schema

The admin plugin adds the following fields to the user table: And adds one field to the session table: