User lifecycle management
An application needs staff to create, update, or remove user accounts through protected administrative APIs.
Better Auth · Function
admin() enables Better Auth's Admin plugin for administrative user management. Add it to the server configuration, then apply the required schema and configure the client plugin when client-side admin operations are needed.
The admin function creates the Better Auth Admin plugin when added to the server configuration. It enables administrative user-management capabilities, including user creation, role changes, banning, impersonation, and deletion; the database schema must also be migrated before using those operations.
admin()A Better Auth Admin plugin instance for use in the plugins configuration.
admin() installs the server-side administrative user-management feature.import { betterAuth } from "better-auth"
import { admin } from "better-auth/plugins"
export const auth = betterAuth({
plugins: [admin()]
})Registers the Admin plugin in a Better Auth server configuration.
An application needs staff to create, update, or remove user accounts through protected administrative APIs.
A support or security team needs to suspend accounts or act as another user for troubleshooting.
A team needs role-based administrative access with optional permission checks for individual operations.
A project is being initialized and requires an initial administrator before the management interface can be used.
Call admin() inside the plugins array passed to betterAuth. After adding it, migrate or generate the database schema and configure the client plugin when client-side admin methods are needed.
Follow-up: How is the first administrator created? Run the Better Auth CLI create-admin command after installing the plugin and applying the schema.
admin() add?The plugin provides administrative user-management operations such as creating users, changing roles, banning or unbanning users, impersonating users, and deleting users. These operations are exposed through the Admin functionality and require an authenticated admin account.
Follow-up: What determines whether a user is an administrator? A user qualifies through the admin role or by having an ID listed in adminUserIds.
admin()?The plugin requires the additional schema fields and tables described by its documentation. Generate or run the migration before using administrative operations, otherwise the database will not contain the required structures.
Follow-up: What should be checked if client methods are unavailable? Ensure the Admin client plugin is also included in the authentication client instance.
createAccessControlhasPermissionadminUserIdscreate-admin