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