better-auth-best-practices
Installation
Summary
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
SKILL.md
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_SECRETandBETTER_AUTH_URL - Create
auth.tswith database + config - Create route handler for your framework
- Run
npx @better-auth/cli@latest migrate - Verify: call
GET /api/auth/ok— should return{ status: "ok" }