Auth.js
The Node/Next-native authentication library. Was NextAuth; renamed Auth.js. Handles OAuth, email-link, credentials.
Mindmap
The plain-English version
Auth.js (formerly NextAuth.js, renamed in v5) is an authentication library for Node web apps, deeply integrated with Next.js. It handles OAuth provider flows (Google, GitHub, etc.), email magic links, and credentials. Sessions can be JWT or database-backed.
The problem it solves
Auth is one of those things you absolutely should not roll yourself. Auth.js has the integrations, the session machinery, and the security defaults already in place. For a Next.js app, it's the path of least resistance — and the path that AI agents reach for confidently.
Alternatives
| Alternative | Type | When it wins |
|---|---|---|
| OAuth 2.0 | protocol | The protocol behind "Sign in with Google." Delegated authorization without giving someone your password. |
Deep links
The words you'll hear
- Provider
- An OAuth source: Google, GitHub, Apple, Discord, etc.
- Adapter
- Database connection for sessions/users. Prisma, Drizzle, MongoDB adapters available.
- Strategy
- Where the session lives —
jwt(in a signed cookie) ordatabase. - Callback
- Hook for customizing what goes in the session/token:
session,jwt,signIn. - Middleware
- Next.js route protection via
authfrom@auth/....
Bad vs. good prompt for Auth.js
Why it works: Specifies the version (v5 has a different API from v4), router (App vs Pages), session strategy, exact files. Eliminates the v4/v5 docs ambiguity that bites everyone.
What bites real teams
Massive API differences. v4 is next-auth; v5 is @auth/next + auth() helper. AI agents mix them. Pin the version explicitly.
JWT vs database changes how callbacks work and what data is available. Pick deliberately.
Each OAuth provider needs the callback URL configured. https://yourapp.com/api/auth/callback/google. Mismatched URLs are 80% of OAuth bugs.