createBetterAuthPlugin
The Payload plugin that creates the Better Auth instance, mounts its endpoints and injects the admin UI. Every option, including admin.login.
createBetterAuthPlugin(options) is a Payload plugin that creates the Better Auth instance in Payload's onInit and attaches it to payload.betterAuth. It registers Better Auth's endpoints under Payload's API route and, when your users collection disables the local strategy, injects the admin login, logout button and security management UI.
import { betterAuth } from 'better-auth'
import { createBetterAuthPlugin, payloadAdapter } from '@delmaredigital/payload-better-auth'
createBetterAuthPlugin({
createAuth: (payload) =>
betterAuth({
...betterAuthOptions,
database: payloadAdapter({ payloadClient: payload }),
}),
admin: {
betterAuthOptions,
login: { title: 'Sign in' },
},
})Options
Prop
Type
See Custom API route for changing routes.api or authBasePath.
admin options
Prop
Type
admin.login options
Options set to 'auto' show the feature when Better Auth has it enabled.
Prop
Type
Related pages: Login and sign-up, Two-factor, Passkeys, Magic link and email OTP, Social sign-in.
Exported helpers
resetAuthInstance()clears the stored auth instance. Useful in tests.getApiKeyPermissionsConfig(payload?)returns theadmin.apiKeyconfig the API keys view uses, preferring the one attached to the given Payload instance.
betterAuthCollections
The Payload plugin that generates auth collections from the installed Better Auth schema. Options, first-user admin, secret fields and customization.
betterAuthStrategy
The Payload auth strategy that validates Better Auth sessions, API keys and OAuth bearer tokens on every Payload request.

