Skip to main content
The Auth0Client class is the main entry point for server-side authentication in your Next.js application.

Constructor

Configuration Options

Required Options

These options can be provided via constructor or environment variables:
string
The Auth0 domain for your tenant (e.g., example.us.auth0.com).Environment variable: AUTH0_DOMAIN
string
The Auth0 client ID for your application.Environment variable: AUTH0_CLIENT_ID
string
The Auth0 client secret for your application.Environment variable: AUTH0_CLIENT_SECRET
Either clientSecret or clientAssertionSigningKey must be provided.
string
A 32-byte, hex-encoded secret used for encrypting cookies.Environment variable: AUTH0_SECRETGenerate with:

Application Configuration

string | string[]
The URL of your application (e.g., http://localhost:3000).Can be a single URL string, or an array of allowed base URLs for multi-domain deployments.Environment variable: APP_BASE_URL (comma-separated for multiple origins)If omitted, the SDK infers the base URL from the request host at runtime.
string
default:"/"
The path to redirect users to after successful authentication.

Authorization Parameters

object
Additional parameters sent to the /authorize endpoint.
Common parameters:
  • scope: OAuth scopes to request
  • audience: API identifier for access token
  • connection: Specific connection to use
  • prompt: Force authentication prompt
boolean
default:false
Enable Pushed Authorization Requests (PAR) for enhanced security.

Session Configuration

SessionConfiguration
Configure session timeouts and rolling behavior.
  • rolling (boolean, default: true): Enable rolling sessions
  • absoluteDuration (number, default: 259200): Absolute session lifetime in seconds (3 days)
  • inactivityDuration (number, default: 86400): Inactivity timeout in seconds (1 day)
  • cookie.name (string, default: __session): Cookie name
  • cookie.secure (boolean): Force HTTPS-only cookies
  • cookie.sameSite (‘lax’ | ‘strict’ | ‘none’, default: ‘lax’)
  • cookie.path (string, default: ’/’)
  • cookie.domain (string): Cookie domain
  • cookie.transient (boolean, default: false): Session-only cookie
SessionDataStore
Custom session store implementation for database-backed sessions.See Session Stores for implementation details.

Logout Configuration

'auto' | 'oidc' | 'v2'
default:"auto"
Strategy for logout endpoint selection:
  • auto: Uses OIDC logout when available, falls back to /v2/logout
  • oidc: Always uses OIDC RP-Initiated Logout
  • v2: Always uses Auth0’s /v2/logout endpoint (supports wildcards)
boolean
default:true
Include id_token_hint parameter in OIDC logout URLs.
When set to false, logout requests lose cryptographic verification. Only disable if privacy requirements outweigh DoS protection concerns.

Token Configuration

number
default:0
Number of seconds to refresh access tokens early before expiration.
boolean
default:true
Enable the /auth/access-token endpoint for client-side token access.
Set to false for Token Mediating Backend pattern where clients don’t need direct token access.

Hooks

function
Manipulate the session before persisting it.
function
Handle errors or manage redirects after authentication callback.

Advanced Options

string | CryptoKey
Private key for private_key_jwt client authentication.Environment variable: AUTH0_CLIENT_ASSERTION_SIGNING_KEY
string
Algorithm for signing client assertion JWT.Environment variable: AUTH0_CLIENT_ASSERTION_SIGNING_ALG
RoutesOptions
Customize authentication route paths.
number
default:5000
HTTP timeout in milliseconds for authentication requests.
boolean
default:true
Send SDK name and version via Auth0-Client header.
boolean
default:false
Allow HTTP requests to authorization server (development only).
Only works when NODE_ENV is not production.
boolean
default:false
Return 204 No Content instead of 401 Unauthorized from /auth/profile when unauthenticated.
boolean
default:false
Enable the /auth/connect endpoint for connecting additional accounts.
Configure transaction cookie for authentication flows.
boolean
default:true
Support multiple concurrent authentication flows with unique transaction cookies.

DPoP Configuration

boolean
default:false
Enable DPoP (Demonstrating Proof-of-Possession) for enhanced OAuth 2.0 security.Requires ES256 key pair via dpopKeyPair or environment variables.
DpopKeyPair
ES256 key pair for DPoP proof generation.
Environment variables:
  • AUTH0_DPOP_PUBLIC_KEY: PEM-encoded public key
  • AUTH0_DPOP_PRIVATE_KEY: PEM-encoded private key
DpopOptions
Configure DPoP timing validation and retry behavior.

MFA Configuration

number
default:300
MFA context TTL in seconds (5 minutes by default).Environment variable: AUTH0_MFA_TOKEN_TTL

Example Configurations

Methods

See the following pages for detailed method documentation:

getSession

Retrieve session data

getAccessToken

Get access tokens

updateSession

Update session data

withPageAuthRequired

Protect pages