auth0-nextjs
Add Auth0 authentication to Next.js apps with session management, protected routes, and middleware.
- Supports both App Router and Pages Router with automatic OAuth callback handling via
/auth/login,/auth/logout, and/auth/callbackendpoints - Provides server-side session access through
auth0.getSession()for Server Components and API routes, plus client-sideuseUser()hook for client components - Requires middleware configuration (
middleware.tsfor Next.js 15+, orproxy.tsfor Next.js 16) to mount authentication routes - Includes optional
<Auth0Provider>wrapper for server-side user hydration and access token retrieval viaauth0.getAccessToken()
Auth0 Next.js Integration
Add authentication to Next.js applications using @auth0/nextjs-auth0. Supports both App Router and Pages Router.
Prerequisites
- Next.js 13+ application (App Router or Pages Router)
- Auth0 account and application configured
- If you don't have Auth0 set up yet, use the
auth0-quickstartskill first
When NOT to Use
- Client-side only React apps - Use
auth0-reactfor Vite/CRA SPAs - React Native mobile apps - Use
auth0-react-nativefor iOS/Android - Non-Next.js frameworks - Use framework-specific SDKs (Express, Vue, Angular, etc.)
- Stateless APIs only - Use JWT validation middleware if you don't need session management
More from auth0/agent-skills
auth0-quickstart
Use when adding authentication or login to any app - detects your stack (React, Next.js, Vue, Nuxt, Angular, Express, Fastify, FastAPI, ASP.NET Core, React Native, Expo, Android, Swift), sets up an Auth0 account if needed, and routes to the correct SDK setup workflow.
1.5Kauth0-react
Use when adding authentication to React applications (login, logout, user sessions, protected routes) - integrates @auth0/auth0-react SDK for SPAs with Vite or Create React App
828auth0-react-native
Use when adding authentication to React Native or Expo mobile apps (iOS/Android) with biometric support - integrates react-native-auth0 SDK with native deep linking
517auth0-express
Use when adding authentication (login, logout, protected routes) to Express.js web applications - integrates express-openid-connect for session-based auth.
416auth0-mfa
Use when adding MFA, 2FA, TOTP, SMS codes, push notifications, passkeys, or when requiring step-up verification for sensitive operations or meeting compliance requirements (HIPAA, PCI-DSS) - covers adaptive and risk-based authentication with Auth0.
400auth0-angular
Use when adding authentication to Angular applications with route guards and HTTP interceptors - integrates @auth0/auth0-angular SDK for SPAs
346