better-auth

Implement Better Auth authentication for Cloudflare D1, Next.js, and TypeScript frameworks.

Updated Jun 22, 2026
One-click install
npx skills add https://github.com/aicodepro/ai-agent-nexi --skill better-auth-aicodepro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth
Source: https://github.com/aicodepro/ai-agent-nexi/tree/main/agent/skills/better-auth
Command: npx skills add https://github.com/aicodepro/ai-agent-nexi --skill better-auth-aicodepro

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth, drizzle-orm, drizzle-kit, kysely, @noxharmonium/kysely-d1, hono, and includes references (resource) and assets (resource) components.

What problem does it solve? Adding authentication to TypeScript applications is error-prone, especially on Cloudflare D1 where adapter misconfigurations, CORS mistakes, and OAuth callback mismatches cause cryptic failures. This Skill provides verified setup patterns, migration guides, and solutions for the 15 most common Better Auth errors. ## Core Features & Use Cases - D1 and Multi-Database Setup: Configure Better Auth with Cloudflare D1 (native or via Drizzle/Kysely), PostgreSQL, MongoDB, or MySQL with correct schema and migrations. - Full Auth Feature Coverage: Implement email/password, 45+ social OAuth providers, 2FA, passkeys, magic links, organizations/RBAC, SSO/SAML, and API keys. - Error Diagnosis and Migration: Resolve D1 adapter errors, CORS issues, and OAuth redirect mismatches, plus step-by-step upgrades for v1.4.0, v1.5.0, and v1.6.0 breaking changes. - Use Case: A developer building a SaaS on Cloudflare Workers needs multi-tenant auth with Google sign-in and 2FA; this Skill walks them through D1 schema, Drizzle adapter setup, organization plugin configuration, and deployment. ## Quick Start Ask the assistant to set up Better Auth with email and Google sign-in on a Cloudflare Worker using D1 and Drizzle.

Frequently Asked Questions about better-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Better Auth with Cloudflare D1?

Create a D1 database with wrangler, define a Drizzle schema, then pass drizzleAdapter(drizzle(env.DB), { provider: "sqlite" }) to betterAuth. In v1.5.0+ you can also pass the D1 binding directly. Generate migrations with drizzle-kit and apply them via wrangler d1 migrations apply.

Why does "d1Adapter is not exported" happen in Better Auth?

There is no d1Adapter export in Better Auth; that import path does not exist. Use drizzleAdapter from better-auth/adapters/drizzle, Kysely with @noxharmonium/kysely-d1, or pass the D1 binding directly in v1.5.0+.

Better Auth vs Clerk vs Auth.js: which should I use?

Better Auth is self-hosted and open source with built-in 2FA, organizations, and passkeys, while Clerk is a paid hosted service and Auth.js offers fewer built-in features. The framework-comparison reference covers feature matrices, migration paths, and cost analysis.

Does Better Auth support Next.js and frameworks other than Cloudflare Workers?

Yes, Better Auth supports 18 frameworks including Next.js, Nuxt, Remix, SvelteKit, Astro, Express, NestJS, Fastify, and Expo. The skill includes framework-specific references for App Router middleware, Nuxt composables, Remix loaders, and mobile SecureStore patterns.

Why do I get CORS or OAuth redirect_uri_mismatch errors with Better Auth?

CORS errors occur when credentials: true is missing from your CORS middleware, blocking session cookies. OAuth mismatches happen when the callback URL differs even slightly, such as a trailing slash; it must exactly match https://yourdomain.com/api/auth/callback/google.

What breaking changes exist when upgrading Better Auth to v1.5 or v1.6?

v1.5.0 moved the API key plugin to @better-auth/api-key, renamed userId to referenceId, and made after-hooks run post-transaction. v1.6.0 changed session freshAge to use createdAt and enabled SAML InResponseTo validation by default. Dedicated migration guides cover each upgrade.