b3nab

payload better auth

by b3nab
payload-better-auth
Authentication & SSO
v3
>=3.0.0 <4.0.0
AGPL-3.0

Overview

Summary generated from the README

Wraps the Better Auth library for Payload CMS 3. It generates Payload collections from your Better Auth options, mounts the auth API endpoints and provides a Payload database adapter for Better Auth. Requires the better-auth and better-auth-harmony peer dependencies and Payload 3.

Features

  • Collections auto-generated from Better Auth options
  • Better Auth API endpoints mounted under the auth path
  • Payload database adapter with transactions, joins and cleanup on delete
  • Two-factor authentication (TOTP) in the admin UI
  • Social login buttons injected into the admin login screen
  • Role-based access with admin and user roles plus Next.js guards

Use cases

  • Add social login and two-factor authentication to a Payload admin and app
  • Replace basic email and password auth with Better Auth in a Payload project
  • Protect Next.js routes using role checks tied to Payload users

From the author

A Payload CMS 3 plugin for Better Auth

Installation

npm i @b3nab/payload-better-auth

74

Stars

3

Forks

1

Open Issues

4 months ago

Last Updated

0

Weekly Downloads

v

npm Version

Dependencies

GitHub stars

74+1 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 202674
Dec 5, 202674
Dec 4, 202674
Dec 3, 202674
Dec 2, 202674
Dec 1, 202674
Nov 30, 202674
Nov 29, 202674
Nov 28, 202674
Nov 27, 202674
Nov 26, 202674
Nov 25, 202674
Nov 24, 202674
Nov 23, 202674
Nov 22, 202674
Nov 21, 202674
Nov 20, 202674
Nov 19, 202674
Nov 18, 202674
Nov 17, 202674
Nov 16, 202674
Nov 15, 202674
Nov 14, 202674
Nov 13, 202674
Nov 12, 202674
Nov 11, 202674
Nov 10, 202674
Nov 9, 202674
Nov 8, 202674
Nov 7, 202674
Nov 6, 202674
Nov 5, 202674
Nov 4, 202674
Nov 3, 202674
Nov 2, 202674
Nov 1, 202674
Oct 31, 202674
Oct 30, 202674
Oct 29, 202674
Oct 28, 202674
Oct 27, 202674
Oct 26, 202674
Oct 25, 202674
Oct 24, 202674
Oct 23, 202674
Oct 22, 202674
Oct 21, 202674
Oct 20, 202674
Oct 19, 202674
Oct 18, 202674
Oct 17, 202674
Oct 16, 202674
Oct 15, 202674
Oct 14, 202674
Oct 13, 202674
Oct 12, 202674
Oct 11, 202674
Oct 10, 202674
Oct 9, 202674
Oct 8, 202674
Oct 7, 202674
Oct 6, 202674
Oct 5, 202674
Oct 4, 202674
Oct 3, 202674
Oct 2, 202674
Oct 1, 202674
Sep 30, 202674
Sep 29, 202674
Sep 28, 202673
Sep 27, 202673
Sep 26, 202673
Sep 25, 202673
Sep 24, 202673
Sep 23, 202673
Sep 22, 202673
Sep 21, 202673
Sep 20, 202673
Sep 19, 202673
Sep 18, 202673
Sep 17, 202673
Sep 16, 202673
Sep 15, 202673
Sep 14, 202673
Sep 13, 202673
Sep 12, 202673
Sep 11, 202673
Sep 10, 202673
Sep 9, 202673
Sep 8, 202673
Sep 7, 202673
npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

Each point is npm's rolling 7-day download count.

Health Score

34/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/931756401-payload-better-auth.svg)](https://payloaddirectory.dev/plugins/931756401-payload-better-auth)
HTML
<a href="https://payloaddirectory.dev/plugins/931756401-payload-better-auth"><img src="https://payloaddirectory.dev/badge/931756401-payload-better-auth.svg" alt="Payload Directory"></a>
Updated Jul 15, 2026Created Feb 12, 2025

README

Payload Better Auth Plugin

A plugin that integrates Better Auth with Payload CMS v3, providing enhanced authentication capabilities. Built to be used in production, with real users, so to be rock solid. ๐Ÿ—ฟ

Documentation ยท Issues

Description

This plugin is a wrapper around the better-auth library. It provides a better-way ๐Ÿค“ to manage authentication for Payload CMS v3.

The goal is to seamlessly integrate better-auth in your Payload CMS v3 application, providing a robust and feature-rich authentication system with a focus on user experience and developer productivity.

Why This Plugin?

While Payload CMS comes with a solid and extensible authentication system out of the box, it primarily focuses on basic email/password authentication and API keys. This serves many use cases well, but modern applications often require more sophisticated authentication methods and features.

Features

  • Payload collections auto-generated from your Better Auth options (JSON fields, dropdowns, hidden secrets, read-only system fields)
  • Better Auth API endpoints mounted for you at /api/auth/*
  • Payload database adapter for Better Auth, with transactions, joins, and automatic cleanup of dependent records on delete
  • payload.betterAuth instance, fully typed with your own plugin options
  • Two-Factor Authentication (TOTP) wired into the Payload admin UI
  • Social login buttons auto-injected into the admin login screen
  • Default email verification and password reset flows (overridable)
  • Role-based access control with admin and user roles out of the box
  • Auth layer helpers for Next.js (checkers, guards)

Important Notes

  1. Contributions via issues and PRs are highly encouraged
  2. Maintainers are not responsible for issues that may occur

License

This project is licensed under the GNU Affero General Public License v3.0. For commercial licensing options, please contact the maintainer.

Installation

Install the plugin and its peer dependencies:

pnpm add @b3nab/payload-better-auth better-auth better-auth-harmony

Quick Start

Create the plugin config in its own file:

// lib/payload-better-auth.config.ts
import { defineBetterAuthPluginOptions } from '@b3nab/payload-better-auth'

export const payloadBetterAuthConfig = defineBetterAuthPluginOptions({
  // Better Auth Config. https://www.better-auth.com/docs/reference/options
  betterAuth: {
    // used by two factor plugin as an issuer and other things
    appName: 'My App',
    // better-auth secret - you can omit it if your env variable is named `BETTER_AUTH_SECRET`
    /** you can generate a good secret
     * using the following command:
     * @example
     * openssl rand -base64 32
     */
    secret: process.env.BETTER_AUTH_SECRET,
  },
})

// makes payload.betterAuth fully typed with YOUR options, everywhere
declare module '@b3nab/payload-better-auth' {
  interface PayloadBetterAuthRegister {
    pluginOptions: typeof payloadBetterAuthConfig
  }
}

Then add the plugin to your payload.config.ts file:

import { buildConfig } from 'payload'
import { betterAuthPlugin } from '@b3nab/payload-better-auth'
import { payloadBetterAuthConfig } from './lib/payload-better-auth.config'

export default buildConfig({

  // ... other config

  plugins: [
    betterAuthPlugin(payloadBetterAuthConfig),

    // ... other plugins

  ],
})

See the documentation for the full setup: custom collections, roles, social providers, email flows, and protected Next.js routes.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Credits

Created by Benedetto Abbenanti

Similar plugins