secondsky/claude-skills/better-auth
- community
Checking that the SKILL.md file is still in the repository.
Skill for integrating Better Auth - comprehensive TypeScript authentication framework for Cloudflare D1, Next.js, Nuxt, and 15+ frameworks. Use when adding auth, encountering D1 adapter errors, or implementing OAuth/2FA/RBAC features.
Install
npx vskill@latest install secondsky/claude-skills/better-authSKILL.md
better-auth
Status: Production Ready Last Updated: 2026-04-08 Package: better-auth@1.6.0 (ESM-only) Dependencies: Drizzle ORM or Kysely (required for D1 complex use cases; D1 native support available in v1.5+)
Quick Start (5 Minutes)
Installation
Option 1: Drizzle ORM (Recommended)
Option 2: Kysely
⚠️ v1.4.0+ Requirements
better-auth v1.4.0+ is ESM-only. Ensure:
package.json:
Upgrading from v1.3.x? Load references/migration-guide-1.4.0.md Upgrading from v1.4.x? Load references/migration-guide-1.5.0.md
⚠️ CRITICAL: D1 Adapter Requirements
v1.5.0+: D1 is now natively supported. Pass your D1 binding directly:
For complex schemas, use Drizzle ORM:
Minimal Setup (Cloudflare Workers + Drizzle)
1. Create D1 Database:
2. Define Schema (src/db/schema.ts):
3. Initialize Auth (src/auth.ts):
4. Create Worker (src/index.ts):
5. Deploy:
Decision Tree
For code examples and syntax, always consult [better-auth.com/docs](https://better-auth.com/docs).
Critical Rules
MUST DO
✅ Use better-auth/minimal + adapter packages for smallest bundle (v1.5+) ✅ Use npx auth migrate and npx auth generate for CLI commands (v1.5+) ✅ Set BETTER_AUTH_SECRET via wrangler secret put ✅ Configure CORS with credentials: true ✅ Match OAuth callback URLs exactly (no trailing slash) ✅ Apply migrations to local D1 before wrangler dev ✅ Use camelCase column names in schema
NEVER DO
❌ Use d1Adapter (doesn't exist) ❌ Forget CORS credentials or mismatch OAuth URLs ❌ Use snake_case columns without CamelCasePlugin ❌ Skip local migrations or hardcode secrets ❌ Leave sendVerificationEmail unimplemented
⚠️ v1.5.0 Breaking Changes
API Key Plugin Moved:
Schema: userId → referenceId, new configId field.
After Hooks: Database after-hooks now run post-transaction (not inside it).
Deprecated APIs Removed: Adapter → DBAdapter, InferUser/InferSession removed, @better-auth/core/utils split into subpath exports.
Load `references/migration-guide-1.5.0.md` when upgrading from <1.5.0
⚠️ v1.6.0 Breaking Changes
Session Freshness: freshAge now uses createdAt (not updatedAt). Sessions may require re-auth more frequently for sensitive operations.
SAML Security: InResponseTo validation is default ON. Opt out with saml: { enableInResponseToValidation: false }.
OIDC Provider Deprecated: Use @better-auth/oauth-provider instead.
New in v1.5.0 (Highlights)
- New CLI:
npx auth init/migrate/generate/upgrade - D1 Native: Pass D1 binding directly (no adapter needed)
- OAuth 2.1 Provider:
@better-auth/oauth-provider(MCP-ready) - Electron:
@better-auth/electronfor desktop apps - i18n:
@better-auth/i18nfor error translations - Dynamic Base URL: Multi-domain/preview deployment support
- Secret Key Rotation: Non-destructive, versioned secrets
- Test Utils: Factories, OTP capture, login helpers
- Typed Error Codes: Machine-readable
codein error responses
Load `references/v1.5-features.md` for detailed implementation guides.
New in v1.6.0 (Highlights)
- OpenTelemetry: Distributed tracing (experimental)
- Passkey Pre-Auth: Register passkeys before session
- Non-blocking Scrypt: Password hashing on libuv thread pool
- 46% Smaller Package: 4.2MB → 2.3MB
- Case Insensitive Queries:
mode: "insensitive"on adapter queries
Load `references/v1.6-features.md` for detailed implementation guides.
Quick Reference
Environment Variables
| Variable | Purpose | Example | |
|---|---|---|---|
BETTER_AUTH_SECRET | Encryption secret (min 32 chars) | Generate: openssl rand -base64 32 | |
BETTER_AUTH_URL | Base URL | https://example.com or http://localhost:8787 | |
DATABASE_URL | Database connection (optional for D1) | PostgreSQL/MySQL connection string |
Note: Only define baseURL/secret in config if env vars are NOT set.
CLI Commands (v1.5+)
| Command | Purpose | |
|---|---|---|
npx auth init | Interactive project scaffolding | |
npx auth migrate | Run database migrations | |
npx auth generate | Generate auth schema | |
npx auth generate --adapter drizzle | Adapter-specific schema | |
npx auth upgrade | Upgrade to latest version | |
bunx drizzle-kit generate | D1: Use this to generate Drizzle migrations | |
wrangler d1 migrations apply DB_NAME | D1: Use this to apply migrations |
Re-run after adding/changing plugins.
Core Config Options
| Option | Notes | |
|---|---|---|
appName | Optional display name | |
baseURL | Only if BETTER_AUTH_URL not set | |
basePath | Default /api/auth. Set / for root. | |
secret | Only if BETTER_AUTH_SECRET not set (min 32 chars) | |
database | Required for most features. Use drizzleAdapter() or Kysely for D1 | |
secondaryStorage | Redis/KV for sessions & rate limits | |
emailAndPassword | { enabled: true } to activate | |
socialProviders | { google: { clientId, clientSecret }, ... } | |
plugins | Array of plugins (import from dedicated paths) | |
trustedOrigins | CSRF whitelist for cross-origin requests |
Common Plugins
Import from dedicated packages (extracted in v1.5+):
Core plugins (still in better-auth/plugins): twoFactor, organization, admin, anonymous, emailOTP, magicLink, phone-number, multi-session, custom-session.
Top 5 Errors (See references/error-catalog.md for all 15)
Error #1: "d1Adapter is not exported"
Problem: Trying to use non-existent d1Adapter Solution: Use drizzleAdapter or Kysely instead (see Quick Start above)
Error #2: Schema Generation Fails
Problem: better-auth migrate doesn't work with D1 Solution: Use bunx drizzle-kit generate then wrangler d1 migrations apply
Error #3: CamelCase vs snake_case Mismatch
Problem: Database uses email_verified but better-auth expects emailVerified Solution: Use camelCase in schema or add CamelCasePlugin to Kysely
Error #4: CORS Errors
Problem: Access-Control-Allow-Origin errors, cookies not sent Solution: Configure CORS with credentials: true and correct origins
Error #5: OAuth Redirect URI Mismatch
Problem: Social sign-in fails with "redirect_uri_mismatch" Solution: Ensure exact match: https://yourdomain.com/api/auth/callback/google
Load `references/error-catalog.md` for all 15 errors with detailed solutions.
Common Use Cases
Use Case 1: Email/Password Authentication
When: Basic authentication without social providers Quick Pattern:
Load: references/setup-guide.md → Step 5
Use Case 2: Social Authentication (45+ Providers)
When: Allow users to sign in with social accounts Supported: Google, GitHub, Microsoft, Apple, Discord, TikTok, Twitch, Spotify, LinkedIn, Slack, Reddit, Facebook, Twitter/X, Patreon, Vercel, Kick, and 30+ more. Quick Pattern:
Load: references/setup-guide.md → Step 5
Use Case 3: Protected API Routes
When: Need to verify user is authenticated Quick Pattern:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 93 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/better-auth/skills/better-auth/SKILL.md
Popularity
- Repository stars
- 216
- Repository forks
- 31
- 7-day trend score
- 27
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 30 Mar 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/secondsky/claude-skills/better-auth)