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_DOMAINstring
The Auth0 client ID for your application.Environment variable:
AUTH0_CLIENT_IDstring
The Auth0 client secret for your application.Environment variable:
AUTH0_CLIENT_SECRETEither
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 Common parameters:
/authorize endpoint.scope: OAuth scopes to requestaudience: API identifier for access tokenconnection: Specific connection to useprompt: Force authentication prompt
boolean
default:false
Enable Pushed Authorization Requests (PAR) for enhanced security.
Session Configuration
SessionConfiguration
Configure session timeouts and rolling behavior.
Session Options
Session Options
rolling(boolean, default:true): Enable rolling sessionsabsoluteDuration(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 namecookie.secure(boolean): Force HTTPS-only cookiescookie.sameSite(‘lax’ | ‘strict’ | ‘none’, default: ‘lax’)cookie.path(string, default: ’/’)cookie.domain(string): Cookie domaincookie.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/logoutoidc: Always uses OIDC RP-Initiated Logoutv2: Always uses Auth0’s/v2/logoutendpoint (supports wildcards)
boolean
default:true
Include
id_token_hint parameter in OIDC logout URLs.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_KEYstring
Algorithm for signing client assertion JWT.Environment variable:
AUTH0_CLIENT_ASSERTION_SIGNING_ALGRoutesOptions
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).
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.Transaction Cookie Configuration
TransactionCookieOptions
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 keyAUTH0_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_TTLExample 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