NextAuth.js v4 → Auth.js v5
mediumAuth.js v5 is the App Router rewrite of NextAuth. Providers work the same but the session API changed significantly.
npm install next-auth@beta
Move config from pages/api/auth/[...nextauth].ts to a top-level auth.ts file.
import NextAuth from 'next-auth'
import GitHub from 'next-auth/providers/github'
export const { auth, handlers, signIn, signOut } = NextAuth({ providers: [GitHub] })Create app/api/auth/[...nextauth]/route.ts using the handlers export.
import { handlers } from '@/auth'
export const { GET, POST } = handlersIn server components: await auth(). Removed getServerSession() — use auth() directly.
import { auth } from '@/auth'
const session = await auth()Use the auth() export from your config directly as middleware, or wrap it.
What this migration involves
Moving from NextAuth.js v4 to Auth.js v5 is rated medium and takes about 2-4h on a typical project. The guide breaks it into 5 steps, 4 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 take?
Around 2-4h for a typical project — 5 steps, difficulty rated medium, 4 of them with copy-paste commands.
Is moving from NextAuth.js v4 to Auth.js 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 cost compared to NextAuth.js v4?
Pricing for both tools is contact-based or not tracked yet.