Skip to Content
Delmare Digital

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.

src/payload.config.ts
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 the admin.apiKey config the API keys view uses, preferring the one attached to the given Payload instance.
Edit this page on GitHub

On this page