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

Better Auth · Pipe

plugins

Better Auth plugins extend the framework with authentication features and custom behavior. Register server plugins in the auth configuration and client plugins when creating the client.

How it works

A Better Auth plugin extends the authentication system with additional behavior. Server plugins are registered in the auth configuration, while client plugins are registered when creating the client; many features need both sides configured.

Syntax

plugins: [plugin(options)]

Key points

  • Plugins extend Better Auth beyond its core authentication behavior.
  • Use plugins to introduce authentication methods, add features, or alter existing behavior.
  • Server registration happens through the auth configuration's plugins array.
  • Pass configuration options when constructing a plugin to control its initialization.
  • Client-side registration belongs in the authentication client setup.
  • A custom plugin can expose endpoints for plugin-specific operations.
  • Plugins can add database schema requirements.

Common mistakes

  • A feature may not function if only its server or client half is installed.
  • Custom server plugins must provide a unique id.

Example: Register a server plugin

import { betterAuth } from "better-auth";
import { twoFactor } from "better-auth/plugins";

export const auth = betterAuth({
  plugins: [twoFactor()]
});

Adds a built-in plugin to the server authentication configuration.

When to use it

Built-in feature integration

Add a built-in authentication feature such as two-factor authentication.

Custom endpoints

Expose plugin-specific routes or operations.

Database customization

Add tables or fields required by an extension.

Request lifecycle customization

Apply route-specific or request-wide behavior.

Interview questions

QHow do you add a server plugin?

question: How do you add a server plugin? Include the plugin instance in the plugins array of the Better Auth configuration. The plugin is initialized with the options passed to it.

Follow-up: question: Can a plugin be client-side only? answer: Yes, plugins can be server-side, client-side, or both, although many require both halves.

QWhat capabilities can a custom plugin provide?

A plugin can define endpoints, extend database schemas, apply middleware or hooks, affect all requests or responses, and add rate-limit rules. These capabilities let it add authentication features or customize existing behavior.

Follow-up: Which mechanism should target a specific route? Use a hook; use middleware when matching a group of routes.

QWhat is required to create a server plugin?

A custom server plugin is an object satisfying the BetterAuthPlugin interface. Its only required property is id, which uniquely identifies the plugin.

Follow-up: What must a client plugin provide? It is added when creating the client and supplies frontend-facing APIs for the server plugin.

  • BetterAuthPlugin
  • endpoints
  • schemas
  • middleware
  • hooks
  • onRequest
  • onResponse
  • rate-limit

Source: Plugins. Checked 2026-10-15.