Clerk → Better Auth
mediumBetter Auth is free and self-hosted. No MAU limits, no vendor lock-in. Best for teams who want full control and hit Clerk's pricing ceiling.
Estimated: 4-8h · 6 steps
Progress0%
Step 1: Install Better Auth
npm install better-auth && npm uninstall @clerk/nextjs
Step 2: Set up auth config
Create auth.ts. Configure database (Drizzle/Prisma), email/password, and OAuth providers.
import { betterAuth } from 'better-auth'
export const auth = betterAuth({ database: drizzleAdapter(db, { provider: 'pg' }) })Step 3: Run database migrations
npx better-auth migrate
Step 4: Replace middleware
Remove Clerk's clerkMiddleware(). Add Better Auth session checking in your middleware.
import { auth } from '@/auth'
const session = await auth.api.getSession({ headers: request.headers })Step 5: Migrate users
Export from Clerk using the Clerk SDK backend. Import to your database with password hashes when available.
Step 6: Update components
Replace Clerk's <SignIn>, <UserButton> with your own or Better Auth's client helpers.
✓ Sign in, sign up, sign out, session persistence all work