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

Better Auth · Type Alias

BetterAuthPlugin

BetterAuthPlugin is the contract for defining a Better Auth server plugin. Its only required property is a unique id; optional plugin features can add endpoints, schemas, hooks, middleware, and other behavior.

How it works

BetterAuthPlugin is the contract used to type-check a server plugin object. A plugin must provide a unique id, while additional capabilities such as endpoints, schemas, hooks, and middleware can extend its behavior.

Syntax

type BetterAuthPlugin = { id: string; ... }

Returns

A server plugin object satisfying the BetterAuthPlugin interface; the page specifically requires the id property.

Key points

  • Use a compatible object as the server plugin implementation and validate it with the BetterAuthPlugin contract.
  • The minimum valid plugin shape contains a unique string identifier.
  • A paired server/client implementation may share one identifier to represent the same feature.
  • Install the server plugin by placing the instantiated plugin in Better Auth’s configuration array.
  • Factory options are applied when Better Auth initializes the configured plugin.
  • The plugin contract supports extending authentication with custom endpoints.

Common mistakes

  • Every server plugin needs a unique id; omitting it means the object does not satisfy the documented contract.
  • Typing a server plugin does not automatically provide its client-side integration; add a client plugin when the feature requires one.

Example: Minimal Better Auth plugin

import type { BetterAuthPlugin } from "better-auth";

export const myPlugin = () => {
  return {
    id: "my-plugin",
  } satisfies BetterAuthPlugin;
};

Defines a minimal server plugin whose required unique identifier is checked against BetterAuthPlugin.

When to use it

Custom server plugin

Create a custom authentication extension with its own server behavior.

Custom endpoints

Add application-specific routes or operations to Better Auth.

Paired server/client plugin

Provide a shared feature implemented on both server and client.

Interview questions

QWhat is BetterAuthPlugin used for?

BetterAuthPlugin is the type contract for a server plugin object. The documented minimum is an id that uniquely identifies the plugin.

Follow-up: What should a reusable plugin do for typed lookup? It can augment BetterAuthPluginRegistry, using a registry key that matches the plugin id.

QHow would you type-check a custom plugin?

Create a plugin factory that returns an object and use satisfies BetterAuthPlugin to validate its shape without losing the inferred type of the returned object.

Follow-up: Why use satisfies rather than a broad annotation? It checks compatibility while preserving more specific inferred property types for later use.

QHow is a BetterAuthPlugin installed?

Register the resulting server plugin in the plugins array of the Better Auth configuration. The plugin initializes with the supplied options when the auth instance is created.

Follow-up: Can a plugin also expose frontend APIs? Yes; pair the server plugin with a client plugin when the feature needs a client-facing interface.

  • createAuthEndpoint
  • BetterAuthPluginRegistry
  • plugins array
  • client plugins

Source: Plugins. Checked 2026-10-15.