delmaredigital

payload better auth

by delmaredigital
Authentication & SSO
v3
v4
>=3.90.0 <4
>=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5 · prerelease
MIT

Overview

Summary generated from the README

Connects Better Auth to Payload by storing auth data in Payload collections through a database adapter and an auth strategy for the users collection. The plugin registers auth endpoints under the API route and adds admin UI components for sign-in, passkeys, two-factor and API keys. It requires Payload 3.90 or later, a recent Better Auth, Next.js 16.4.1 or later and Node 22.23.4 or later.

Features

  • Payload database adapter for Better Auth with atomic single-use token and counter operations on Postgres
  • Auth strategy for the users collection that forwards refreshed session cookies on REST and GraphQL requests
  • Generated auth collections and a first-user-admin hook for role assignment
  • Configurable role field with access helpers such as isAdmin, hasRole and isAdminOrSelf
  • Server-side session helper and typed client with two-factor and passkey support
  • Migration helper for converting stringified array fields to native arrays

Use cases

  • Replace Payload's local login strategy with Better Auth email and password sign-in
  • Add passkeys, two-factor and magic link login to a Payload and Next.js site
  • Gate admin panel access by user role while keeping sessions in the Payload database

From the author

Better Auth adapter and plugins for Payload CMS

Installation

npm i @delmaredigital/payload-better-auth

77

Stars

13

Forks

0

Open Issues

5 days ago

Last Updated

10.9k

Weekly Downloads

v0.14.3

npm Version

614.0 KB

Unpacked Size

2

Dependencies

GitHub stars

77+11 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 202677
Dec 5, 202677
Dec 4, 202677
Dec 3, 202677
Dec 2, 202676
Dec 1, 202676
Nov 30, 202676
Nov 29, 202676
Nov 28, 202676
Nov 27, 202676
Nov 26, 202676
Nov 25, 202676
Nov 24, 202676
Nov 23, 202676
Nov 22, 202676
Nov 21, 202676
Nov 20, 202676
Nov 19, 202675
Nov 18, 202675
Nov 17, 202675
Nov 16, 202675
Nov 15, 202675
Nov 14, 202675
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, 202672
Oct 17, 202672
Oct 16, 202671
Oct 15, 202671
Oct 14, 202671
Oct 13, 202671
Oct 12, 202671
Oct 11, 202670
Oct 10, 202670
Oct 9, 202670
Oct 8, 202668
Oct 7, 202668
Oct 6, 202668
Oct 5, 202668
Oct 4, 202668
Oct 3, 202668
Oct 2, 202668
Oct 1, 202668
Sep 30, 202668
Sep 29, 202668
Sep 28, 202668
Sep 27, 202668
Sep 26, 202668
Sep 25, 202668
Sep 24, 202668
Sep 23, 202668
Sep 22, 202668
Sep 21, 202668
Sep 20, 202668
Sep 19, 202668
Sep 18, 202668
Sep 17, 202667
Sep 16, 202667
Sep 15, 202667
Sep 14, 202667
Sep 13, 202666
Sep 12, 202666
Sep 11, 202666
Sep 10, 202666
Sep 9, 202666
Sep 8, 202666
Sep 7, 202666
npm weekly downloads

10.9K+8.6K since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202610,914
Dec 5, 20269,314
Dec 4, 20267,296
Dec 3, 20265,494
Dec 2, 20264,607
Dec 1, 20264,279
Nov 30, 20264,183
Nov 29, 20264,672
Nov 28, 20264,890
Nov 27, 20264,898
Nov 26, 20264,466
Nov 25, 20264,434
Nov 24, 20264,479
Nov 23, 20264,451
Nov 22, 20263,974
Nov 21, 20263,947
Nov 20, 20264,200
Nov 19, 20264,352
Nov 18, 20264,704
Nov 17, 20264,805
Nov 16, 20264,816
Nov 15, 20264,708
Nov 14, 20264,593
Nov 13, 20264,427
Nov 12, 20264,389
Nov 11, 20263,775
Nov 10, 20263,863
Nov 9, 20263,835
Nov 8, 20263,861
Nov 7, 20263,981
Nov 6, 20263,632
Nov 5, 20263,261
Nov 4, 20263,229
Nov 3, 20263,063
Nov 2, 20263,120
Nov 1, 20263,096
Oct 31, 20263,238
Oct 30, 20263,101
Oct 29, 20262,674
Oct 28, 20262,137
Oct 27, 20261,975
Oct 26, 20261,993
Oct 25, 20261,959
Oct 24, 20261,727
Oct 23, 20261,360
Oct 22, 20261,683
Oct 21, 20262,130
Oct 20, 20262,094
Oct 19, 20262,076
Oct 18, 20262,057
Oct 17, 20262,149
Oct 16, 20262,799
Oct 15, 20263,146
Oct 14, 20263,352
Oct 13, 20263,299
Oct 12, 20263,364
Oct 11, 20263,496
Oct 10, 20263,571
Oct 9, 20263,477
Oct 8, 20263,290
Oct 7, 20263,016
Oct 6, 20263,013
Oct 5, 20262,877
Oct 4, 20262,648
Oct 3, 20262,325
Oct 2, 20262,122
Oct 1, 20261,998
Sep 30, 20262,398
Sep 29, 20262,448
Sep 28, 20262,485
Sep 27, 20262,577
Sep 26, 20262,661
Sep 25, 20262,975
Sep 24, 20263,165
Sep 23, 20262,950
Sep 22, 20263,140
Sep 21, 20263,223
Sep 20, 20263,307
Sep 19, 20263,394
Sep 18, 20263,141
Sep 17, 20263,018
Sep 16, 20262,917
Sep 15, 20262,810
Sep 14, 20262,831
Sep 13, 20263,226
Sep 12, 20262,996
Sep 11, 20262,908
Sep 10, 20262,928
Sep 9, 20262,606
Sep 8, 20262,448
Sep 7, 20262,271

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

Health Score

90/100Excellent

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/1127884946-root.svg)](https://payloaddirectory.dev/plugins/1127884946-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1127884946-root"><img src="https://payloaddirectory.dev/badge/1127884946-root.svg" alt="Payload Directory"></a>
Updated Nov 30, 2026Created Jan 4, 2026Published Nov 30, 2026

README

@delmaredigital/payload-better-auth

Better Auth adapter and plugins for Payload CMS. Enables seamless integration between Better Auth and Payload.

Starter Template - Use This

Deploy with Vercel

Documentation: plugins.delmaredigital.com/docs/better-auth · Overview

⚠️ 0.14.0 raises the minimum peer versions, for security fixes only. Better Auth >=1.7.7 (critical Magic Link account takeover, fixed 1.7.7), Next.js >=16.4.1 (two critical RCEs, fixed 16.4.1), Payload >=3.90.0 (about twenty advisories, several critical, fixed 3.90.0) and Node >=22.23.4 (Node 20 is end-of-life and unpatched). The plugin's own behaviour is unchanged. If you applied the 0.11.0 account.issuer migration, run the cleanup migration first (Better Auth 1.7.3 reverted that schema; see below). If you cannot upgrade a peer yet, stay on 0.13.2 and apply the upstream workarounds; details and links in the CHANGELOG.

Payload 4

Payload 4 is in beta, and we're supporting it early. This plugin is a thin adapter. It talks to Payload only through its public Local API and admin UI exports, so a new Payload major means a small set of mechanical changes rather than a rewrite. We follow Payload's canary releases as they land, and we intend to have a stable release ready when Payload 4.0 ships.

You runInstallnpm tag
Payload 3 (>=3.90 <4)pnpm add @delmaredigital/payload-better-authlatest (0.14.x)
Payload 4 beta (>=4.0.0-canary.37)pnpm add @delmaredigital/payload-better-auth@nextnext (0.40.0-next.x)

Trying it on Payload 4:

  • Requirements: payload / @payloadcms/ui >=4.0.0-canary.37, next >=16.2.6, Node >=24.15, plus the rest of Payload's v4 migration guide. Better Auth requirements are unchanged.
  • Pin an exact version (e.g. @delmaredigital/[email protected]). Prereleases follow Payload's canaries and can change from one build to the next.
  • Already handled, on both majors: the plugin's Local API lookups pass overrideAccess: true explicitly (Payload 4 flips the default to false), and its generated auth collections opt out of Payload 4's default versioning, so you get no _versions tables holding old sessions, tokens or password hashes.
  • Known gap: the plugin's admin screens (passkeys, two-factor, API keys) still use Payload 3's --theme-* CSS variables, which Payload 4 retires, so their styling is off. Sign-in, sessions and access control are unaffected.
  • Where the work happens: the payload-4 branch. Please report problems in an issue with "Payload 4" in the title.

The next line is a prerelease, renumbered from 0.14.0-next.x to 0.40.0-next.x with the 0.14.0 release so the two lines can never collide; pin 0.40.0-next.0 or later. For production, stay on latest until Payload 4.0 is stable; at that point the Payload 4 line becomes latest, and 0.14.x stays installable for Payload 3.

Upgrading from 0.12 to 0.13? No code, config or data changes are needed; 0.13.0 is not breaking, despite the minor bump. One behavior to know: payload.auth({ headers }) no longer extends the session unless you pass canSetHeaders: true and forward responseHeaders, so a call that can't deliver a refreshed cookie is now a pure read. 0.13.2 adds the optional roleField setting.

Upgrading from 0.11 or earlier? Read the upgrade guide before you bump. 0.11 requires Better Auth 1.7, and 0.12 changed how array fields are stored (migration steps). Every release's details are in the CHANGELOG.

Already ran the 0.11.0 account.issuer migration? Better Auth 1.7.3 reverted that schema. Before moving past Better Auth 1.7.2, drop the NOT NULL on issuer and the unique (issuer, accountId) index, or sign-ups and account links fail. Details in the CHANGELOG.


Documentation

For AI-assisted exploration: DeepWiki


Install

pnpm add @delmaredigital/payload-better-auth better-auth

Requirements: payload >= 3.90.0 · better-auth >= 1.7.7 · next >= 16.4.1 · react >= 19.2.1 · Node >= 22.23.4

Quick Start

1. Auth Configuration

// src/lib/auth/config.ts
import type { BetterAuthOptions } from 'better-auth'

export const betterAuthOptions: Partial<BetterAuthOptions> = {
  user: {
    additionalFields: {
      // `input: false` keeps `role` server-only — clients cannot set it at
      // sign-up. Role is assigned by the first-user-admin hook; configure the
      // default self-sign-up role via `firstUserAdmin: { defaultRole }`.
      role: { type: 'string', defaultValue: 'user', input: false },
    },
  },
  emailAndPassword: { enabled: true },
}

2. Users Collection

// src/collections/Users/index.ts
import type { CollectionConfig } from 'payload'
import { betterAuthStrategy } from '@delmaredigital/payload-better-auth'

export const Users: CollectionConfig = {
  slug: 'users',
  auth: {
    disableLocalStrategy: true,
    strategies: [betterAuthStrategy()],
  },
  access: {
    read: ({ req }) => {
      if (!req.user) return false
      if (req.user.role === 'admin') return true
      return { id: { equals: req.user.id } }
    },
    admin: ({ req }) => req.user?.role === 'admin',
  },
  fields: [
    { name: 'email', type: 'email', required: true, unique: true },
    { name: 'emailVerified', type: 'checkbox', defaultValue: false },
    { name: 'name', type: 'text' },
    { name: 'image', type: 'text' },
    {
      name: 'role',
      type: 'select',
      defaultValue: 'user',
      options: [
        { label: 'User', value: 'user' },
        { label: 'Admin', value: 'admin' },
      ],
    },
  ],
}

Every additionalFields entry needs a matching field here. Scalars map to the obvious Payload type; an array-typed one (string[] / number[]) needs a field that stores an array — json, or select with hasMany: true — because the adapter writes real arrays, not serialized ones:

// better auth: roles: { type: 'string[]' }
{ name: 'roles', type: 'json' }

Naming the role field

The plugin reads roles from user.role by default. To keep them somewhere else, such as a roles array, set roleField once on betterAuthCollections():

betterAuthCollections({ betterAuthOptions, roleField: 'roles' })

The first-user-admin guard, the saveToJWT field list, the access helpers, the admin login role gate and the API-key management gate all read that value. firstUserAdmin.roleField is the older spelling of the same setting and still works. For types, wrap the generated user: WithRoleField<User, 'roles', string[]>.

Better Auth's fieldName mapping (role: { type: 'string', fieldName: 'roles' }) renames where the value is stored, and the adapter handles it. Here that stored name is also the Payload field name, so Payload-side checks see user.roles while Better Auth's session user keeps role. Set roleField to the stored name ('roles'); the admin login gate translates it to the session key on its own. Use fieldName when you want the column renamed under Better Auth's key; use roleField when the property itself is called something else.

Called directly, hasAnyRole(user, roles) and hasAllRoles(user, roles) still default to role for backward compatibility — with a custom field, pass the name as the third argument (hasAnyRole(user, ['admin'], 'roles')) or the check reads the wrong property. The access helpers (isAdmin, hasRole, isAdminOrSelf, …) do this for you: they read the configured roleField off the request's Payload config and also accept a roleField option of their own.

roleField is published by betterAuthCollections(), so setups that skip it have no configured value and every gate falls back to role. To use another name there, either set it on your Payload config yourself (custom: { betterAuth: { roleField: 'roles' } }) or pass roleField to each helper and the roleField prop to a standalone LoginView.

Upgrading from 0.11.x with the oauth-provider plugin or an array-typed additionalField? Those columns hold JSON strings and need converting once — see Migrating stringified arrays.

3. Payload Config

// src/payload.config.ts
import { buildConfig } from 'payload'
import { postgresAdapter } from '@payloadcms/db-postgres'
import { betterAuth } from 'better-auth'
import {
  betterAuthCollections,
  createBetterAuthPlugin,
  payloadAdapter,
} from '@delmaredigital/payload-better-auth'
import { betterAuthOptions } from './lib/auth/config'
import { Users } from './collections/Users'
import { getBaseUrl } from './lib/auth/getBaseUrl'

const baseUrl = getBaseUrl()

export default buildConfig({
  collections: [Users],
  plugins: [
    betterAuthCollections({
      betterAuthOptions,
      skipCollections: ['user'],
    }),
    createBetterAuthPlugin({
      createAuth: (payload) =>
        betterAuth({
          ...betterAuthOptions,
          database: payloadAdapter({ payloadClient: payload }),
          advanced: { database: { generateId: 'serial' } },
          baseURL: baseUrl,
          secret: process.env.BETTER_AUTH_SECRET,
          trustedOrigins: [baseUrl],
        }),
    }),
  ],
  db: postgresAdapter({
    pool: { connectionString: process.env.DATABASE_URL },
  }),
})

4. Client-Side Auth

// src/lib/auth/client.ts
'use client'

import { createAuthClient, twoFactorClient } from '@delmaredigital/payload-better-auth/client'
import { passkeyClient } from '@better-auth/passkey/client'

export const authClient = createAuthClient({
  plugins: [twoFactorClient(), passkeyClient()],
})

export const { useSession, signIn, signUp, signOut, twoFactor, passkey } = authClient

Listing plugins inline (rather than using createPayloadAuthClient() or spreading payloadAuthPlugins) ensures twoFactor and other plugin methods are typed on the returned client.

5. Server-Side Session

import { headers } from 'next/headers'
import { getPayload } from 'payload'
import { getServerSession } from '@delmaredigital/payload-better-auth'

export default async function Dashboard() {
  const payload = await getPayload({ config })
  const headersList = await headers()
  const session = await getServerSession(payload, headersList)

  if (!session) { redirect('/login') }

  return <div>Hello {session.user.name}</div>
}

Sessions slide the way Better Auth documents (session.updateAge): once the refresh window is reached, getSession() extends the session row and issues a refreshed cookie. betterAuthStrategy forwards that Set-Cookie on every Payload REST and GraphQL request, so the browser's cookie moves with the database. Where there is no response to carry a cookie — server components, getServerSession(), payload.auth({ headers }) — the session is read without refreshing it, so the two can never drift apart. To let a Local API call refresh the session, tell Payload it may set headers and forward what it hands back:

// app/api/whoami/route.ts
export async function GET(req: Request) {
  const payload = await getPayload({ config })
  const { user, responseHeaders } = await payload.auth({ headers: req.headers, canSetHeaders: true })
  return Response.json({ user }, { headers: responseHeaders })
}

That's it! The plugin automatically registers auth API endpoints at /api/auth/*, injects admin UI components, and handles session management.

Using a non-default API route? The plugin mounts Better Auth at routes.api + authBasePath, and Better Auth's own router 404s any request outside its basePath (default /api/auth). If your Payload config sets routes: { api: '/api/payload' }, tell Better Auth where it lives:

// inside createAuth
betterAuth({
  basePath: '/api/payload/auth', // <routes.api> + <authBasePath>
  // ...
})

The plugin's admin components pick up routes.api automatically, and the plugin logs an error at startup (naming the exact value to set) if basePath doesn't match the mount.


Atomic operations

Better Auth 1.7 requires every database adapter to implement two atomic primitives, and calls them on paths you are almost certainly using:

PrimitiveUsed by
consumeOneSingle-use credentials — email verification, password reset, magic links, email OTP, device-authorization codes
incrementOneGuarded counters — API-key quota and rate limits, two-factor backup codes, team member counts

On Postgres, eligible flat collections and supported predicates use one guarded SQL statement through Payload's existing Drizzle connection:

  • consumeOne uses DELETE … RETURNING, returning the row only to the caller whose statement removed it.
  • incrementOne uses UPDATE … SET counter = COALESCE(counter, 0) + delta … RETURNING, so concurrent increments accumulate without a read-then-write race. Both statements select at most one identity and re-assert the caller's guard on the outer write, where Postgres rechecks it after waiting for a concurrent writer. A guard miss returns null.

Configure this behavior with adapterConfig.atomicWrites:

payloadAdapter({
  payloadClient: payload,
  adapterConfig: { atomicWrites: 'auto' }, // default
})
ModePath selection for incrementOne and consumeOne
'auto' (default)Uses atomic Postgres when the sanitized collection has no trash, versions/drafts, or collection/field hooks other than field beforeDuplicate. Nested fields and read hooks are included in the check; empty hook arrays are allowed. Each refusal warns once per collection and reason, then uses the non-atomic Local API.
'always'Allows atomic Postgres even with hooks, after application review. Throws if an otherwise eligible collection/request cannot run atomically. Trash and versions/drafts still require the Local API, with a warning once per collection and reason.
'never'Always uses the Local API.

The atomic SQL path does not run Payload collection or field hooks. This includes validation, change, delete, operation, and read hooks. For a hook-only refusal, review the hooks before choosing 'always' to bypass them. Payload's default beforeDuplicate hooks on unique fields do not disqualify a collection because they never run on update/delete. Admin baseFilter/baseListFilter do not apply to these Local API operations and do not disqualify atomic writes. Virtual, join, and ui fields have no stored columns and are ignored during column eligibility checks.

The policy inspects sanitized collection configuration once per collection and caches its decision for the adapter instance; configure collections before using the adapter. Policy refusals in 'auto' and 'always' always emit console.warn once per collection and distinct reason. SQL compatibility failures (missing connection/table/column metadata, unsupported stored fields or writes, untranslatable predicates) always emit console.error once per collection and distinct reason. In 'auto', these failures use the Local API and its concurrency limits; 'always' throws instead. With enableDebugLogs: true, the adapter additionally logs the first atomic execution and first fallback per collection. Other adapter methods continue to use the Local API.

Under 'always', an untranslatable predicate shape introduced by a future Better Auth release will throw until this adapter is patched, which is why 'auto' is the default.

Dependency: drizzle-orm is a regular dependency pinned to 0.45.2, matching Payload 3.92.1, and is installed automatically with this package; no consumer action is needed. Static imports include atomic SQL in production Next.js/Vercel/standalone bundles without runtime adapter-package discovery. A compatibility test compares our pin with the installed dev Payload dependency. Separately, the daily Payload Drizzle canary compares the latest published @payloadcms/drizzle requirement with our pin and opens or updates an issue labelled payload-drizzle-canary on drift, even before we bump dev Payload.

Fallback and limits: Other stores keep the existing Local API path. On Postgres, unsupported stored shapes (such as localized or has-many fields) and untranslatable predicates log an error and fall back in 'auto', or throw in 'always'. Supported predicates are scalar eq, ne, lt, lte, gt, gte, and scalar-array in, with the existing AND/OR grouping and explicit NULL semantics. Unsupported predicates include nested paths, JSON predicates, insensitive mode, and other operators.

Malformed IDs are handled more strictly than Payload's query builder, which validates primary-key UUIDs but passes relationship UUIDs through: here invalid UUIDs or nonnumeric serial primary/relationship IDs never match, including for ne. This prevents an invalid exclusion from broadening a credential write to all non-null rows. Explicit null keeps its existing semantics. The Local API fallback reads before deleting by id or updating with a compare-and-swap guard (up to five attempts); Payload can resolve that guard before its internal write, so concurrent calls can still lose counter updates or consume a token more than once.

Migrating stringified arrays (0.12.0)

Releases up to 0.11.3 reported supportsArrays: false to Better Auth, so every string[] / number[] value was JSON.stringify'd on its way into Payload. Those columns hold '["a","b"]' where an array belongs. From 0.12.0 the adapter stores arrays natively, so those rows need converting once.

If you don't use the oauth-provider plugin and have no array-typed additionalFields, there is nothing to do — nothing else in Better Auth uses an array field.

Use 0.12.1 or later. On 0.12.0 this migration was a silent no-op on Postgres: it reported converted: 0 against databases that were not clean. Payload writes these fields to a jsonb column, so a stringified value is stored as a jsonb string; on read node-postgres parses the jsonb and hands drizzle a JS string, and drizzle's PgJsonb.mapFromDriverValue parses it a second time. The stored string becomes an array before Payload sees it, so a stringified row and a native one are indistinguishable through payload.find(). 0.12.1 censuses the stored shape in SQL instead. If you ran the 0.12.0 migration, re-run it.

1. Migrate

import { migrateStringifiedArrays } from '@delmaredigital/payload-better-auth'
import { betterAuthOptions } from './lib/auth/config'

const results = await migrateStringifiedArrays({
  payload,
  betterAuthOptions,
  dryRun: true, // drop this once the report looks right
})
console.table(results)
// [{ collection: 'oauthClients', field: 'redirectUris', scanned: 12,
//    converted: 12, skipped: 0, observedVia: 'stored-shape' }, …]

It derives the fields to convert from your own Better Auth schema rather than a hardcoded list, so it covers whatever plugins you run, and it's safe to re-run — values already stored as arrays are left alone, and a string that doesn't parse to an array is skipped and counted rather than guessed at.

Read observedVia alongside converted. On Postgres it must say stored-shape; local-api there would mean the count came from the laundered value and is not trustworthy. If the stored shape can't be inspected at all, the migration throws rather than reporting a clean database.

2. Verify against the database

converted: 0 is only good news if the census could see the stored shape. Confirm independently:

SELECT jsonb_typeof(scopes) AS shape, count(*)
FROM oauth_access_tokens GROUP BY 1;

You want only array (and null). Any string rows are unconverted. To fix them outside the plugin:

UPDATE oauth_access_tokens
SET scopes = (scopes #>> '{}')::jsonb
WHERE jsonb_typeof(scopes) = 'string';

3. Only then, remove your own workarounds

If you were writing JSON.stringify(uris) into these columns, or parsing them back out on read, drop that — after migrating, the column holds one shape.

Do this last, and only after step 2 reads clean. Removing a tolerant parse while unconverted rows remain is what turns this into an incident: raw SQL reads carry no column type, so they bypass drizzle's mapper and still see the string. Code that reads redirect_uris via drizzle.execute(sql…) — a DCR connector gate, a consent screen — would get [] from an unconverted row. For a redirect-URI allowlist that's a hard lockout of a legitimate connector.

That raw-SQL path is also the real exposure of leaving rows unmigrated. Better Auth's own reads go through Payload, where the double-parse launders the value, so /oauth2/authorize keeps working — the damage is confined to code that queries these columns directly.

Upgrading Better Auth

Generated collections follow the installed Better Auth schema. With the SQL adapters (Postgres/SQLite), after any better-auth bump, including a patch, run payload migrate:create and read the diff before deploying. A new NOT NULL column on a populated table needs a backfill before enforcing the constraint; a proposed column drop needs you to confirm nothing still reads it.

payload migrate:create compares against the last migration's snapshot, rather than the live database. An empty migration does not prove the database matches; check the actual columns if in doubt. Dev push mode applies the same changes without asking.

This repo keeps schema snapshots and runs a daily CI canary against the latest Better Auth to catch drift. The CHANGELOG documents the Better Auth schema changes this repo detects; review it alongside your own migration diff.


For MongoDB setup, API reference, customization, access control helpers, API key scopes, plugin compatibility, UI components (2FA, passkeys, password reset, passwordless login via magic-link & email-OTP), recipes, and types — see the full documentation.

License

MIT

Similar plugins