/auth/logout route. The SDK supports multiple logout strategies and configuration options.
Basic Logout
The simplest way to log users out is to redirect them to the logout route:/auth/logout, the SDK will:
- Clear the local session cookie
- Redirect to Auth0’s logout endpoint
- Return to your application (or a specified URL)
Logout Strategies
The SDK supports three logout strategies that control which Auth0 logout endpoint is used.Auto Strategy (Default)
Theauto strategy uses OIDC logout when available, falling back to Auth0’s /v2/logout endpoint:
lib/auth0.ts
- If Auth0 supports OIDC logout (
end_session_endpointis available), uses OIDC - Otherwise, falls back to
/v2/logout - Recommended for most applications
OIDC Strategy
Always use OIDC RP-Initiated Logout:lib/auth0.ts
- You want to enforce OIDC logout
- Your Auth0 tenant supports OIDC logout
- You need strict compliance with OIDC standards
This strategy will return an error if OIDC logout is not supported by your authorization server.
V2 Strategy
Always use Auth0’s/v2/logout endpoint:
lib/auth0.ts
- You need wildcard URL support in logout redirects
- Supporting multiple languages or environments with dynamic URLs
- Migrated from v3 and need existing logout URL patterns
- Have complex logout URL requirements incompatible with OIDC
Return URL After Logout
Redirect users to a specific URL after logout using thereturnTo parameter.
Basic Return URL
Relative URLs
Use relative URLs to redirect within your application:Dynamic Return URLs
Build dynamic logout URLs based on the current page:Federated Logout
Log users out from both Auth0 and their identity provider (e.g., Google, Facebook, SAML).Enable Federated Logout
Add thefederated parameter to the logout URL:
With Return URL
Combine federated logout with a return URL:- The
federatedparameter works with all logout strategies (auto,oidc,v2) - For OIDC logout:
https://your-domain.auth0.com/oidc/logout?federated&... - For V2 logout:
https://your-domain.auth0.com/v2/logout?federated&...
Federated logout requires the identity provider to support logout. Not all providers support this feature.
OIDC Logout Privacy Configuration
Control whether theid_token_hint parameter is included in OIDC logout URLs.
Default Behavior (Recommended)
By default, the SDK includesid_token_hint for enhanced security:
lib/auth0.ts
Privacy-Focused Configuration
Excludeid_token_hint from logout URLs to prevent PII from appearing in logs:
lib/auth0.ts
- The SDK still sends
logout_hintandclient_idparameters - Reduces security against DoS attacks (per OIDC spec)
- Useful when PII in server logs is unacceptable
This flag only affects the
oidc or auto (uses oidc when possible) logout strategy. It has no effect with the v2 strategy.Logout Flow Examples
- App Router
- Pages Router
Create a logout button in a Server Component:Or use a simple link:
app/components/logout-button.tsx
app/components/nav.tsx
Best Practices
- Always use server-side navigation for logout (use
<a>tags, not<Link>) - Register all return URLs in Auth0 Dashboard Allowed Logout URLs
- Use relative URLs when possible to avoid hardcoding domains
- Choose the appropriate strategy based on your requirements:
autofor most applicationsv2for wildcard URL supportoidcfor strict OIDC compliance
- Use federated logout only when users expect to be logged out of the IdP
Troubleshooting
Logout redirect not working
If users aren’t redirected after logout:- Check Allowed Logout URLs: Ensure the return URL is registered in your Auth0 Application settings
- Verify URL encoding: Use
encodeURIComponent()for dynamic URLs - Check logout strategy: Ensure your strategy is compatible with your URL patterns
Wildcard URLs not working
If wildcard URLs aren’t working:- Switch to
logoutStrategy: "v2"(OIDC doesn’t support wildcards) - Register the wildcard pattern in Allowed Logout URLs
Users still logged into IdP
If users remain logged into their identity provider:- Add the
federatedparameter to the logout URL - Verify the IdP supports federated logout
- Check that federated logout is enabled in your Auth0 configuration
Privacy concerns with id_token_hint
If you’re concerned about PII in logout URLs:- Set
includeIdTokenHintInOIDCLogoutUrl: false - Understand the security trade-offs (reduced DoS protection)
- Only use this option when privacy is a critical requirement