Skip to content
Home / Migrations / NextAuth.js v4Auth.js v5

NextAuth.js v4 Auth.js v5

medium

Auth.js v5 is the App Router rewrite of NextAuth. Providers work the same but the session API changed significantly.

Estimated: 2-4h · 5 steps
Progress0%
Step 1: Update package
npm install next-auth@beta
Step 2: Update auth config

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] })
Step 3: Add route handler

Create app/api/auth/[...nextauth]/route.ts using the handlers export.

import { handlers } from '@/auth'
export const { GET, POST } = handlers
Step 4: Update session access

In server components: await auth(). Removed getServerSession() — use auth() directly.

import { auth } from '@/auth'
const session = await auth()
Step 5: Update middleware

Use the auth() export from your config directly as middleware, or wrap it.

Sign in, session access, sign out all work in App Router

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.

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.