Production-ready authentication framework for TypeScript with first-class Cloudflare D1 support. Use this skill when building auth systems as a self-hosted alternative to Clerk or Auth.js, particularly for Cloudflare Workers projects. Supports social providers (Google, GitHub, Microsoft, Apple), email/password, magic links, 2FA, passkeys, organizations, and RBAC. Prevents 10+ common authentication errors including session serialization issues, CORS misconfigurations, D1 adapter setup, social provider OAuth flows, and JWT token handling. Keywords: better-auth, authentication, cloudflare d1 auth, self-hosted auth, typescript auth, clerk alternative, auth.js alternative, social login, oauth providers, session management, jwt tokens, 2fa, two-factor, passkeys, webauthn, multi-tenant auth, organizations, teams, rbac, role-based access, google auth, github auth, microsoft auth, apple auth, magic links, email password, better-auth setup, session serialization error, cors auth, d1 adapter
Production-ready authentication for TypeScript with Cloudflare D1 support
Provides complete patterns for implementing authentication with better-auth, a comprehensive TypeScript auth framework. Includes first-class support for Cloudflare Workers + D1, making it an excellent self-hosted alternative to Clerk or Auth.js.
This skill should be automatically invoked when you mention:
✅ Use this skill when:
❌ Don't use this skill when:
scripts/setup-d1.sh - Automated D1 database setupreferences/cloudflare-worker-example.ts - Complete Worker implementationreferences/nextjs-api-route.ts - Next.js patternsreferences/react-client-hooks.tsx - React componentsreferences/drizzle-schema.ts - Database schemaassets/auth-flow-diagram.md - Visual flow diagramsimport { betterAuth } from 'better-auth'
import { d1Adapter } from 'better-auth/adapters/d1'
import { Hono } from 'hono'
type Env = {
DB: D1Database
BETTER_AUTH_SECRET: string
}
const app = new Hono<{ Bindings: Env }>()
app.all('/api/auth/*', async (c) => {
const auth = betterAuth({
database: d1Adapter(c.env.DB),
secret: c.env.BETTER_AUTH_SECRET,
emailAndPassword: { enabled: true },
socialProviders: {
google: {
clientId: c.env.GOOGLE_CLIENT_ID,
clientSecret: c.env.GOOGLE_CLIENT_SECRET
}
}
})
return auth.handler(c.req.raw)
})
export default app
| Feature | better-auth | Clerk | Auth.js | |---------|-------------|-------|---------| | Hosting | Self-hosted | Third-party | Self-hosted | | Cost | Free | $25/mo+ | Free | | Cloudflare D1 | ✅ First-class | ❌ No | ✅ Adapter | | 2FA/Passkeys | ✅ Plugin | ✅ Built-in | ⚠️ Limited | | Organizations | ✅ Plugin | ✅ Built-in | ❌ No | | Vendor Lock-in | ✅ None | ❌ High | ✅ None |
better-auth@1.3.34npm install better-auth
# or
pnpm add better-auth
# or
yarn add better-auth
For Cloudflare D1:
npm install @cloudflare/workers-types
For PostgreSQL:
npm install pg drizzle-orm
MIT (same as better-auth)
Questions? Check the official docs or ask Claude Code to invoke this skill!
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer