Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables. Use when users mention…
Complete Better Auth server and client setup with database adapters, session management, plugins, and security configuration.
Covers full workflow from installation through database migration, environment variable setup, and route handler creation across multiple frameworks
Supports multiple database adapters (Prisma, Drizzle, MongoDB, direct connections) with critical guidance on model vs. table naming conventions
Includes session storage strategies with secondary storage (Redis/KV), cookie caching modes (compact, JWT, JWE), and stateless operation options
Provides 10+ popular plugins (two-factor, organization, passkey, magic link, OAuth provider, SSO) with tree-shaking imports and client-side integration
Features before/after hooks at endpoint and database levels, rate limiting configuration, CSRF/origin security controls, and type-safe client methods across vanilla, React, Vue, Svelte, and Solid frameworks
Better Auth Integration Guide
Always consult better-auth.com/docs for code examples and latest API.
Setup Workflow
Install: npm install better-auth
Set env vars: BETTER_AUTH_SECRET and BETTER_AUTH_URL
Create auth.ts with database + config
Create route handler for your framework
Run migrations:
Built-in adapter: npx @better-auth/cli@latest migrate
Drizzle: npx @better-auth/cli@latest generate --output src/db/auth-schema.ts then npx drizzle-kit push (dev) or npx drizzle-kit generate && npx drizzle-kit migrate (prod)
Prisma: npx @better-auth/cli@latest generate --output prisma/schema.prisma then npx prisma migrate dev
Verify: call GET /api/auth/ok — should return { status: "ok" }don't have the plugin yet? install it then click "run inline in claude" again.