Auth0Client can be customized using configuration options passed to the constructor or via environment variables.
Basic Setup
Required Configuration
The Auth0 domain for your tenant (e.g.,
example.us.auth0.com or https://example.us.auth0.com).Environment variable: AUTH0_DOMAINThe Auth0 client ID for your application.Environment variable:
AUTH0_CLIENT_IDA 32-byte, hex-encoded secret used for encrypting cookies. Generate using:Environment variable:
AUTH0_SECRETThe Auth0 client secret. Required unless using
clientAssertionSigningKey.Environment variable: AUTH0_CLIENT_SECRETOptional Configuration
Application Settings
The URL of your application (e.g.,
http://localhost:3000).If omitted, the SDK will infer it from the request host at runtime. This is useful for dynamic preview environments (Vercel, Netlify).Environment variable: APP_BASE_URLSecurity note: When using dynamic base URLs in production, the SDK enforces secure cookies. Explicitly setting secure=false will throw InvalidConfigurationError.The path to redirect users to after successful authentication.
Send library name and version to your authorization server via the
Auth0-Client header.HTTP timeout in milliseconds for authentication requests.
Allow insecure requests to the authorization server (useful for testing with mock OIDC providers).Note: Can only be used when
NODE_ENV is not set to production.Authorization Parameters
Authorization parameters to pass to the See Passing authorization parameters for more details.
/authorize endpoint.Logout Configuration
Strategy for logout endpoint selection:
auto: Uses OIDC logout when available, falls back to/v2/logoutoidc: Always uses OIDC logoutv2: Always uses/v2/logoutendpoint which supports wildcard URLs
Configure whether to include
id_token_hint in OIDC logout URLs.true(recommended): Includes ID token for better DoS protectionfalse: Excludes PII from logout URLs but reduces DoS protection
Session Configuration
Configure session timeouts, rolling sessions, and cookie attributes.Cookie environment variables:
AUTH0_COOKIE_DOMAINAUTH0_COOKIE_PATHAUTH0_COOKIE_TRANSIENTAUTH0_COOKIE_SECUREAUTH0_COOKIE_SAME_SITE
httpOnly is always true for security.See Session Configuration and Cookie Configuration for details.Custom session store implementation for persisting sessions to an external data store.See Database sessions for details.
Transaction Cookies
Enable support for multiple concurrent authentication flows.
true: Each authentication attempt gets its own transaction cookie with a unique state suffixfalse: Uses a single shared transaction cookie (may cause conflicts with concurrent auth attempts)
Configure transaction cookie management for authentication flows.See Transaction Cookie Configuration for details.
Advanced OAuth
Private key for use with
private_key_jwt clients.Environment variable: AUTH0_CLIENT_ASSERTION_SIGNING_KEYThe algorithm used to sign the client assertion JWT.Environment variable:
AUTH0_CLIENT_ASSERTION_SIGNING_ALGConfigure the SDK to use Pushed Authorization Requests (PAR) protocol when communicating with the authorization server.
DPoP (Demonstrating Proof-of-Possession)
Enable DPoP for enhanced security. When enabled, the client will generate DPoP proofs for token requests and protected resource requests.DPoP binds access tokens to cryptographic key pairs, preventing token theft and replay attacks.
ES256 key pair for DPoP proof generation.If not provided, the SDK will attempt to load keys from environment variables:
AUTH0_DPOP_PUBLIC_KEY(PEM format)AUTH0_DPOP_PRIVATE_KEY(PEM format)
Configure DPoP timing validation to handle clock differences between client and server.Environment variables:
AUTH0_DPOP_CLOCK_SKEW: Clock adjustment in secondsAUTH0_DPOP_CLOCK_TOLERANCE: Tolerance in seconds
Custom Routes
Hooks
A method to handle errors or manage redirects after attempting to authenticate.See onCallback for details.
Access Token Configuration
Enable the
/auth/access-token endpoint for client-side access token retrieval.Disable this if you don’t need access tokens on the client-side.Refresh access tokens this many seconds before they expire.Useful for ensuring tokens don’t expire mid-request.
Base Path Configuration
Set this environment variable when your Next.js application uses a base path (configured via
basePath in next.config.js).Example: If set to /dashboard, authentication routes will be mounted at:/dashboard/auth/login/dashboard/auth/callback/dashboard/auth/logout
NEXT_PUBLIC_BASE_PATH with an APP_BASE_URL that contains a path component. Set APP_BASE_URL to the root URL and use NEXT_PUBLIC_BASE_PATH for the base path.Configuration Validation
The SDK validates required configuration options when initializing theAuth0Client. Missing required options will result in a warning with details on how to provide them.
Required options:
domainorAUTH0_DOMAINclientIdorAUTH0_CLIENT_IDsecretorAUTH0_SECRET- Either:
clientSecretorAUTH0_CLIENT_SECRET, ORclientAssertionSigningKeyorAUTH0_CLIENT_ASSERTION_SIGNING_KEY
appBaseUrlorAPP_BASE_URL(inferred from request if omitted)
Environment Variables Summary
| Variable | Description | Required |
|---|---|---|
AUTH0_DOMAIN | Auth0 tenant domain | Yes |
AUTH0_CLIENT_ID | Application client ID | Yes |
AUTH0_CLIENT_SECRET | Application client secret | Yes* |
AUTH0_SECRET | Session encryption key (32 chars min) | Yes |
APP_BASE_URL | Application base URL | No** |
AUTH0_CLIENT_ASSERTION_SIGNING_KEY | Private key for private_key_jwt | No |
AUTH0_CLIENT_ASSERTION_SIGNING_ALG | Client assertion signing algorithm | No |
AUTH0_COOKIE_DOMAIN | Cookie domain | No |
AUTH0_COOKIE_PATH | Cookie path | No |
AUTH0_COOKIE_TRANSIENT | Transient cookie flag | No |
AUTH0_COOKIE_SECURE | Secure cookie flag | No |
AUTH0_COOKIE_SAME_SITE | SameSite cookie attribute | No |
AUTH0_DPOP_PUBLIC_KEY | DPoP public key (PEM) | No |
AUTH0_DPOP_PRIVATE_KEY | DPoP private key (PEM) | No |
AUTH0_DPOP_CLOCK_SKEW | DPoP clock adjustment (seconds) | No |
AUTH0_DPOP_CLOCK_TOLERANCE | DPoP validation tolerance (seconds) | No |
NEXT_PUBLIC_BASE_PATH | Next.js base path | No |
AUTH0_CLIENT_ASSERTION_SIGNING_KEY
** Inferred from request host if omitted