Auth0 → Better Auth
mediumBetter Auth is a self-hosted TypeScript-first auth library. Free, open-source, no MAU limits. Best for apps wanting full control without vendor lock-in.
Estimated: 4-8h · 6 steps
Progress0%
Step 1: Install Better Auth
npm install better-auth
Step 2: Set up the auth config
Create auth.ts at project root. Configure database adapter (Drizzle, Prisma, or Kysely), providers, and session settings.
import { betterAuth } from 'better-auth'
export const auth = betterAuth({ database: { provider: 'pg', url: process.env.DATABASE_URL }, emailAndPassword: { enabled: true } })Step 3: Run migrations
Better Auth manages its own tables. Use the CLI to generate and run migrations.
npx better-auth migrate
Step 4: Add API route
Mount the Better Auth handler in your framework's catch-all route.
// Next.js app/api/auth/[...all]/route.ts
import { auth } from '@/auth'
export const { GET, POST } = auth.handlerStep 5: Migrate users
Export users from Auth0 Management API. Import to your database, hashing passwords with bcrypt or argon2 as configured.
Step 6: Update client code
Use the Better Auth React/Vue/Svelte client. Replace useUser, signIn, signOut hooks.
npm install better-auth/client
✓ Sign in/up/out work, sessions persist