Skip to content
Home / Migrations / NextAuth.js / Auth.jsBetter Auth

NextAuth.js / Auth.js Better Auth

medium

Better Auth is framework-agnostic, plugin-based, and offers full type safety end-to-end. NextAuth's complexity around adapters and callbacks goes away.

Estimated: 3-6h · 5 steps
Progress0%
Step 1: Install Better Auth
npm uninstall next-auth @auth/* && npm install better-auth
Step 2: Create auth instance

Replace [...nextauth]/route.ts with a single auth.ts.

import { betterAuth } from 'better-auth'
import { drizzleAdapter } from 'better-auth/adapters/drizzle'
export const auth = betterAuth({ database: drizzleAdapter(db), emailAndPassword: { enabled: true } })
Step 3: Mount API handler

Create app/api/auth/[...all]/route.ts with auth.handler.

import { auth } from '@/auth'
export const { GET, POST } = auth.handler
Step 4: Migrate session usage

useSession() / getServerSession() → auth.api.getSession({ headers }) on server, authClient.useSession() on client.

Step 5: Add OAuth providers

socialProviders: { github: { clientId, clientSecret } } — config moves into the betterAuth() call.

Sign-in flow works for email/password and OAuth. Sessions persist across reloads.