Skip to content
Home / Migrations / Clerk → Better Auth

Clerk → Better Auth

medium

Better 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

What this migration involves

Moving from Clerk to Better Auth is rated medium and takes about 4-8h on a typical project. The guide breaks it into 6 steps, 4 of which ship with runnable commands and 1 with a verification check. On pricing, Clerk is freemium and Better Auth is open-source with a free plan to test the move.

FAQ

How long does migrating from Clerk to Better Auth take?

Around 4-8h for a typical project — 6 steps, difficulty rated medium, 4 of them with copy-paste commands.

Is moving from Clerk to Better Auth reversible?

No reverse guide is tracked yet, so treat this as a one-way move and keep a full export of your Clerk data before you start.

What does Better Auth cost compared to Clerk?

Clerk: freemium from $25/mo, free plan available. Better Auth: open-source from $0/mo, free plan available.