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.
npm install next-auth@beta
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: [...] })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 } = handlersgetServerSession(authOptions) → auth() from your auth.ts. useSession hook still works in Client Components.
session/jwt callback signatures updated. User object shape changed — check adapter docs.
What this migration involves
Moving from NextAuth.js v4 to Auth.js v5 (next-auth v5) is rated medium and takes about 3-8h on a typical project. The guide breaks it into 5 steps, 3 of which ship with runnable commands and 1 with a verification check.
Related migrations
FAQ
How long does migrating from NextAuth.js v4 to Auth.js v5 (next-auth v5) take?
Around 3-8h for a typical project — 5 steps, difficulty rated medium, 3 of them with copy-paste commands.
Is moving from NextAuth.js v4 to Auth.js v5 (next-auth v5) reversible?
No reverse guide is tracked yet, so treat this as a one-way move and keep a full export of your NextAuth.js v4 data before you start.
What does Auth.js v5 (next-auth v5) cost compared to NextAuth.js v4?
Pricing for both tools is contact-based or not tracked yet.