Custom server plugin
Create a custom authentication extension with its own server behavior.
Better Auth · Type Alias
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.
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.
type BetterAuthPlugin = { id: string; ... }A server plugin object satisfying the BetterAuthPlugin interface; the page specifically requires the id property.
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.
Create a custom authentication extension with its own server behavior.
Add application-specific routes or operations to Better Auth.
Provide a shared feature implemented on both server and client.
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.
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.
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.
createAuthEndpointBetterAuthPluginRegistryplugins arrayclient plugins