Skip to content
Home / Migrations / NextAuth.js v4Auth.js v5 (next-auth v5)

NextAuth.js v4 Auth.js v5 (next-auth v5)

medium

Auth.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 } = handlers
Step 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

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.

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.