Skip to main content
The Auth0 Next.js SDK provides a comprehensive server-side API for handling authentication in both the App Router and Pages Router.

Installation

Import the server API from the dedicated server package:

Auth0Client Instance

Create a single instance of Auth0Client to use throughout your application:
lib/auth0.ts

Core Methods

Session Management

getSession

Retrieve the current user’s session data

updateSession

Update session data for authenticated users

Token Management

getAccessToken

Get access tokens with automatic refresh

Session Stores

Configure stateless or stateful session storage

Route Protection

withPageAuthRequired

Protect pages and redirect unauthenticated users

App Router vs Pages Router

The SDK provides different method signatures depending on your Next.js routing strategy:

Router Compatibility

Environment Variables

The SDK requires the following environment variables:
string
required
Your Auth0 tenant domain (e.g., example.us.auth0.com)
string
required
Your Auth0 application client ID
string
required
Your Auth0 application client secret
string
required
A 32-byte hex-encoded secret for encrypting cookies. Generate with:
string
Your application’s base URL (e.g., http://localhost:3000). If omitted, the SDK infers it from the request host at runtime.

Next Steps

Auth0Client Configuration

Learn about all constructor options

Session Data

Understand the session structure