Key concepts
Domain parameter
All Auth0 SDKs require adomain parameter that specifies which Auth0 domain to use for authentication. When using custom domains, set this parameter to your custom domain instead of your Auth0 canonical domain.
Without custom domain:
Token issuer
When using a custom domain, tokens will have theiss (issuer) claim set to your custom domain:
Authentication SDKs
Auth0 SPA SDK (JavaScript)
For single-page applications using the Auth0 SPA SDK:Next.js
For Next.js applications using the Auth0 Next.js SDK (v4+): Key concepts for MCD with Next.js:- Single Auth0 tenant, multiple domains: All custom domains share the same
clientIdandclientSecretsince they belong to the same Auth0 tenant. - DomainResolver function: The
domainparameter accepts a function(config: { headers: Headers; url?: URL }) => Promise<string> | string. This allows dynamic domain resolution per request based on the incoming request headers. - Instance caching: The SDK automatically caches
Auth0Clientinstances per domain using a bounded LRU cache (max 100 entries) for performance. - Session isolation: Sessions created via one custom domain are isolated to that domain and cannot be used interchangeably with sessions from another domain.
- URL parameter: The
urlparameter in the resolver isundefinedin Server Components and Server Actions; it is only available in middleware or API routes. - Discovery cache tuning: Configure OIDC metadata caching with the
discoveryCacheoption:
Auth0 React SDK
For React applications using the Auth0 React SDK:Auth0.js
For applications using Auth0.js:Node.js (Express)
For Node.js applications using express-openid-connect:Mobile SDKs
iOS (Swift)
Using Auth0.swift:Android (Kotlin)
Using Auth0.Android:React Native
Using react-native-auth0:Flutter
Using flutter_auth0:Management SDKs
Management SDKs are used to interact with the Auth0 Management API. When using custom domains, you may need to include theauth0-custom-domain header or use the default domain.
Node.js Management SDK
Python Management SDK
Go Management SDK
Token validation
When using custom domains, update your token validation to accept the custom domain as the issuer.Node.js (Express)
Using express-jwt or jose:Python (Flask)
Using python-jose:Java (Spring Boot)
Using Spring Security:Environment-specific configuration
Use environment variables to manage custom domains across environments:.env file structure
Loading configuration
Troubleshooting
Common issues
| Issue | Cause | Solution |
|---|---|---|
| Invalid issuer error | Token validation expects canonical domain but receives custom domain | Update token validation to accept custom domain as issuer |
| JWKS fetch fails | JWKS URI points to canonical domain | Update JWKS URI to use custom domain: https://custom-domain/.well-known/jwks.json |
| Redirect URI mismatch | Callback URL doesn’t match configured redirect URIs | Add custom domain callback URL to application settings |
| Cross-origin errors (CORS) | Custom domain not in allowed origins | Add custom domain to Allowed Web Origins in application settings |
| Lock fails to load | Missing configurationBaseUrl | Add configurationBaseUrl parameter with regional CDN URL |
Best practices
- Use environment variables: Store custom domains in environment-specific configuration files
- Validate multiple issuers: If using multiple custom domains, configure token validation to accept all as valid issuers
- Update callback URLs: Ensure all custom domains are added to Allowed Callback URLs in application settings
- Test thoroughly: Test authentication flows through each custom domain before going to production
- Monitor token issuers: Log and monitor the
issclaim in tokens to ensure correct custom domain usage - Document domain mappings: Maintain clear documentation of which applications use which custom domains
- Handle failures gracefully: Implement proper error handling for authentication failures
- Cache JWKS: Cache JWKS data to improve performance and reduce requests