
Better Auth Best Practices
Configure Better Auth server and client, set up database adapters, manage sessions, add...
Install
npx skills add trycompai/crm --skill better-auth-best-practices -g -a claude-code -y- Repository
- trycompai/crm11.8k
- Category
- Data and ML
- Updated
- 4d ago
- License
- MIT
- Context cost
- Mediumabout 1,764 tokens
- Runs scripts
- No, instructions only
What it does
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables. Use when users mention Better Auth, betterauth, auth.ts, or need to set up TypeScript authentication with email/password, OAuth, or plugin configuration.
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 migrations:
- Built-in adapter:
npx @better-auth/cli@latest migrate - Drizzle:
npx @better-auth/cli@latest generate --output src/db/auth-schema.tsthennpx drizzle-kit push(dev) ornpx drizzle-kit generate && npx drizzle-kit migrate(prod) - Prisma:
npx @better-auth/cli@latest generate --output prisma/schema.prismathennpx prisma migrate dev
- Built-in adapter:
- Verify: call
GET /api/auth/ok, should return{ status: "ok" }
Quick Reference
Environment Variables
BETTER_AUTH_SECRET- Encryption secret (min 32 chars). Generate:openssl rand -base64 32BETTER_AUTH_URL- Base URL (e.g.,https://example.com)
Only define baseURL/secret in config if env vars are NOT set.
File Location
CLI looks for auth.ts in: ./, ./lib, ./utils, or under ./src. Use --config for custom path.
CLI Commands
npx @better-auth/cli@latest migrate- Apply schema (built-in adapter)npx @better-auth/cli@latest generate- Generate schema for Prisma/Drizzlenpx @better-auth/cli mcp --cursor- Add MCP to AI tools
Re-run after adding/changing plugins.
