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:The Auth0 domain for your tenant (e.g.,
example.us.auth0.com).Environment variable: AUTH0_DOMAINThe Auth0 client ID for your application.Environment variable:
AUTH0_CLIENT_IDThe Auth0 client secret for your application.Environment variable:
AUTH0_CLIENT_SECRETEither
clientSecret or clientAssertionSigningKey must be provided.A 32-byte, hex-encoded secret used for encrypting cookies.Environment variable:
AUTH0_SECRETGenerate with:Application Configuration
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.The path to redirect users to after successful authentication.
Authorization Parameters
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
Enable Pushed Authorization Requests (PAR) for enhanced security.
Session Configuration
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
Custom session store implementation for database-backed sessions.See Session Stores for implementation details.
Logout Configuration
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)
Include
id_token_hint parameter in OIDC logout URLs.Token Configuration
Number of seconds to refresh access tokens early before expiration.
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
Manipulate the session before persisting it.
Handle errors or manage redirects after authentication callback.
Advanced Options
Private key for
private_key_jwt client authentication.Environment variable: AUTH0_CLIENT_ASSERTION_SIGNING_KEYAlgorithm for signing client assertion JWT.Environment variable:
AUTH0_CLIENT_ASSERTION_SIGNING_ALGCustomize authentication route paths.
HTTP timeout in milliseconds for authentication requests.
Send SDK name and version via
Auth0-Client header.Allow HTTP requests to authorization server (development only).
Return
204 No Content instead of 401 Unauthorized from /auth/profile when unauthenticated.Enable the
/auth/connect endpoint for connecting additional accounts.Transaction Cookie Configuration
Configure transaction cookie for authentication flows.
Support multiple concurrent authentication flows with unique transaction cookies.
DPoP Configuration
Enable DPoP (Demonstrating Proof-of-Possession) for enhanced OAuth 2.0 security.Requires ES256 key pair via
dpopKeyPair or environment variables.ES256 key pair for DPoP proof generation.Environment variables:
AUTH0_DPOP_PUBLIC_KEY: PEM-encoded public keyAUTH0_DPOP_PRIVATE_KEY: PEM-encoded private key
Configure DPoP timing validation and retry behavior.
MFA Configuration
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