NextAuth.js v4 → Auth.js v5 (next-auth v5)
mediumAuth.js v5 is a ground-up rewrite of NextAuth v4. Framework-agnostic, App Router native, Edge-compatible. The API surface changed significantly but migration guides are thorough.
Estimated: 3-8h · 5 steps
Progress0%
Step 1: Update package
npm install next-auth@beta
Step 2: Create auth.ts
Move [...nextauth] route config to a top-level auth.ts file. Export { handlers, auth, signIn, signOut }.
import NextAuth from 'next-auth'
export const { handlers, auth, signIn, signOut } = NextAuth({ providers: [...] })Step 3: Update route handler
Replace pages/api/auth/[...nextauth].ts with app/api/auth/[...nextauth]/route.ts using the handlers export.
import { handlers } from '@/auth'
export const { GET, POST } = handlersStep 4: Update session access
getServerSession(authOptions) → auth() from your auth.ts. useSession hook still works in Client Components.
Step 5: Migrate callbacks
session/jwt callback signatures updated. User object shape changed — check adapter docs.
✓ Sign in, sign out, session access all work in both Client and Server Components