{"id":36501395,"url":"https://github.com/delmaredigital/payload-better-auth","last_synced_at":"2026-05-11T21:03:05.261Z","repository":{"id":331945495,"uuid":"1127884946","full_name":"delmaredigital/payload-better-auth","owner":"delmaredigital","description":"Better Auth adapter and plugins for Payload CMS","archived":false,"fork":false,"pushed_at":"2026-04-17T02:23:26.000Z","size":437,"stargazers_count":49,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-04-17T04:30:42.623Z","etag":null,"topics":["authentication","better-auth","nextjs","payload-plugin","payloadcms","plugin","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@delmaredigital/payload-better-auth","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/delmaredigital.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-04T19:27:15.000Z","updated_at":"2026-04-17T02:23:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/delmaredigital/payload-better-auth","commit_stats":null,"previous_names":["delmaredigital/payload-better-auth"],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/delmaredigital/payload-better-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delmaredigital%2Fpayload-better-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delmaredigital%2Fpayload-better-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delmaredigital%2Fpayload-better-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delmaredigital%2Fpayload-better-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/delmaredigital","download_url":"https://codeload.github.com/delmaredigital/payload-better-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delmaredigital%2Fpayload-better-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32912661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-11T17:09:15.040Z","status":"ssl_error","status_checked_at":"2026-05-11T17:08:45.420Z","response_time":120,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","better-auth","nextjs","payload-plugin","payloadcms","plugin","typescript"],"created_at":"2026-01-12T02:21:59.734Z","updated_at":"2026-05-11T21:03:05.255Z","avatar_url":"https://github.com/delmaredigital.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @delmaredigital/payload-better-auth\n\nBetter Auth adapter and plugins for Payload CMS. Enables seamless integration between Better Auth and Payload.\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://demo.delmaredigital.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/Live_Demo-Try_It_Now-2ea44f?style=for-the-badge\u0026logo=vercel\u0026logoColor=white\" alt=\"Live Demo - Try It Now\"\u003e\u003c/a\u003e\n  \u0026nbsp;\u0026nbsp;\n  \u003ca href=\"https://github.com/delmaredigital/dd-starter\"\u003e\u003cimg src=\"https://img.shields.io/badge/Starter_Template-Use_This-blue?style=for-the-badge\u0026logo=github\u0026logoColor=white\" alt=\"Starter Template - Use This\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fdelmaredigital%2Fdd-starter\u0026project-name=my-payload-site\u0026build-command=pnpm%20run%20ci\u0026env=PAYLOAD_SECRET,BETTER_AUTH_SECRET\u0026stores=%5B%7B%22type%22%3A%22integration%22%2C%22protocol%22%3A%22storage%22%2C%22productSlug%22%3A%22neon%22%2C%22integrationSlug%22%3A%22neon%22%7D%2C%7B%22type%22%3A%22blob%22%7D%5D\"\u003e\u003cimg src=\"https://vercel.com/button\" alt=\"Deploy with Vercel\" height=\"32\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003e ⚠️ **Upgrading to 0.7?** This release requires **Better Auth 1.6** and includes several breaking changes:\n\u003e\n\u003e - **Schema migration required** for projects using the `twoFactor` plugin — Better Auth 1.6.2 added a `verified` column to the `twoFactor` table.\n\u003e - **`oidcProvider` → `@better-auth/oauth-provider`** — generated OAuth types now reflect the `oauth-provider` schema. Consumers using `oidcProvider()` at runtime will keep working, but `OauthApplication` / `PluginId` / `ModelKey` type exports have changed shape. Migrating to `@better-auth/oauth-provider` is recommended.\n\u003e - **Client helper type widening** — `createPayloadAuthClient()` and `payloadAuthPlugins` are typed more conservatively to keep `.d.ts` portable. For typed plugin methods (e.g. `client.twoFactor.verifyTotp`), list plugins explicitly in `createAuthClient({ plugins: [...] })` (see [Client-Side Auth](#4-client-side-auth) below).\n\u003e\n\u003e See the [CHANGELOG](./CHANGELOG.md#070---2026-04-21) for full migration instructions.\n\n---\n\n## Documentation\n\n**[Full Documentation](https://delmaredigital.github.io/payload-better-auth/)** — API reference, guides, recipes, UI components, and more.\n\nFor AI-assisted exploration: [DeepWiki](https://deepwiki.com/delmaredigital/payload-better-auth)\n\n---\n\n## Install\n\n```bash\npnpm add @delmaredigital/payload-better-auth better-auth\n```\n\n**Requirements:** `payload` \u003e= 3.69.0 · `better-auth` \u003e= 1.6.0 · `next` \u003e= 15.4.8 · `react` \u003e= 19.2.1\n\n## Quick Start\n\n### 1. Auth Configuration\n\n```ts\n// src/lib/auth/config.ts\nimport type { BetterAuthOptions } from 'better-auth'\n\nexport const betterAuthOptions: Partial\u003cBetterAuthOptions\u003e = {\n  user: {\n    additionalFields: {\n      role: { type: 'string', defaultValue: 'user' },\n    },\n  },\n  emailAndPassword: { enabled: true },\n}\n```\n\n### 2. Users Collection\n\n```ts\n// src/collections/Users/index.ts\nimport type { CollectionConfig } from 'payload'\nimport { betterAuthStrategy } from '@delmaredigital/payload-better-auth'\n\nexport const Users: CollectionConfig = {\n  slug: 'users',\n  auth: {\n    disableLocalStrategy: true,\n    strategies: [betterAuthStrategy()],\n  },\n  access: {\n    read: ({ req }) =\u003e {\n      if (!req.user) return false\n      if (req.user.role === 'admin') return true\n      return { id: { equals: req.user.id } }\n    },\n    admin: ({ req }) =\u003e req.user?.role === 'admin',\n  },\n  fields: [\n    { name: 'email', type: 'email', required: true, unique: true },\n    { name: 'emailVerified', type: 'checkbox', defaultValue: false },\n    { name: 'name', type: 'text' },\n    { name: 'image', type: 'text' },\n    {\n      name: 'role',\n      type: 'select',\n      defaultValue: 'user',\n      options: [\n        { label: 'User', value: 'user' },\n        { label: 'Admin', value: 'admin' },\n      ],\n    },\n  ],\n}\n```\n\n### 3. Payload Config\n\n```ts\n// src/payload.config.ts\nimport { buildConfig } from 'payload'\nimport { postgresAdapter } from '@payloadcms/db-postgres'\nimport { betterAuth } from 'better-auth'\nimport {\n  betterAuthCollections,\n  createBetterAuthPlugin,\n  payloadAdapter,\n} from '@delmaredigital/payload-better-auth'\nimport { betterAuthOptions } from './lib/auth/config'\nimport { Users } from './collections/Users'\nimport { getBaseUrl } from './lib/auth/getBaseUrl'\n\nconst baseUrl = getBaseUrl()\n\nexport default buildConfig({\n  collections: [Users],\n  plugins: [\n    betterAuthCollections({\n      betterAuthOptions,\n      skipCollections: ['user'],\n    }),\n    createBetterAuthPlugin({\n      createAuth: (payload) =\u003e\n        betterAuth({\n          ...betterAuthOptions,\n          database: payloadAdapter({ payloadClient: payload }),\n          advanced: { database: { generateId: 'serial' } },\n          baseURL: baseUrl,\n          secret: process.env.BETTER_AUTH_SECRET,\n          trustedOrigins: [baseUrl],\n        }),\n    }),\n  ],\n  db: postgresAdapter({\n    pool: { connectionString: process.env.DATABASE_URL },\n  }),\n})\n```\n\n### 4. Client-Side Auth\n\n```ts\n// src/lib/auth/client.ts\n'use client'\n\nimport { createAuthClient, twoFactorClient } from '@delmaredigital/payload-better-auth/client'\nimport { passkeyClient } from '@better-auth/passkey/client'\n\nexport const authClient = createAuthClient({\n  plugins: [twoFactorClient(), passkeyClient()],\n})\n\nexport const { useSession, signIn, signUp, signOut, twoFactor, passkey } = authClient\n```\n\n\u003e Listing plugins inline (rather than using `createPayloadAuthClient()` or spreading `payloadAuthPlugins`) ensures `twoFactor` and other plugin methods are typed on the returned client.\n\n### 5. Server-Side Session\n\n```ts\nimport { headers } from 'next/headers'\nimport { getPayload } from 'payload'\nimport { getServerSession } from '@delmaredigital/payload-better-auth'\n\nexport default async function Dashboard() {\n  const payload = await getPayload({ config })\n  const headersList = await headers()\n  const session = await getServerSession(payload, headersList)\n\n  if (!session) { redirect('/login') }\n\n  return \u003cdiv\u003eHello {session.user.name}\u003c/div\u003e\n}\n```\n\n**That's it!** The plugin automatically registers auth API endpoints at `/api/auth/*`, injects admin UI components, and handles session management.\n\n---\n\nFor MongoDB setup, API reference, customization, access control helpers, API key scopes, plugin compatibility, UI components (2FA, passkeys, password reset), recipes, and types — see the **[full documentation](https://delmaredigital.github.io/payload-better-auth/)**.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelmaredigital%2Fpayload-better-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdelmaredigital%2Fpayload-better-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelmaredigital%2Fpayload-better-auth/lists"}