Choose One Version and Router

Check your installed package with npm ls next-auth. The main examples use v4: pages/api/auth/[...nextauth].js, NextAuth(authOptions), getServerSession(req, res, authOptions), and callbackUrl. Auth.js v5 commonly uses auth.ts, exports handlers and auth, and uses auth() in server contexts. Do not mix snippets across major versions.

Version compatibility

The current Auth.js documentation describes v5 and later in many places. Use the v4 docs for the runnable v4 implementation in this tutorial.