Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Function

admin

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.

How it works

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.

Syntax

admin()

Returns

A Better Auth Admin plugin instance for use in the plugins configuration.

Key points

  • admin() installs the server-side administrative user-management feature.
  • Its scope covers account creation, role administration, bans, impersonation, and related user actions.
  • The function is used as a plugin entry in the Better Auth configuration.
  • Client-side administrative helpers require the corresponding Admin client plugin as well.

Common mistakes

  • Admin endpoints require an authenticated administrator before they can be used.
  • Applying the generated or migrated schema is required before relying on the plugin's persistence fields and tables.
  • Administrator status can come from the admin role or from the configured administrator user-ID list.

Example: Enable the Admin plugin

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.

When to use it

User lifecycle management

An application needs staff to create, update, or remove user accounts through protected administrative APIs.

Moderation and support operations

A support or security team needs to suspend accounts or act as another user for troubleshooting.

Administrative authorization

A team needs role-based administrative access with optional permission checks for individual operations.

Bootstrap the first admin

A project is being initialized and requires an initial administrator before the management interface can be used.

Interview questions

QHow do you enable the Admin plugin?

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.

QWhat capabilities does 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.

QWhat setup is required beyond calling 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.

  • createAccessControl
  • hasPermission
  • adminUserIds
  • create-admin

Source: Admin | Better Auth. Checked 2026-10-15.