Route Overview
All routes are mounted under the/auth prefix by default:
Route Details
/auth/login
Initiates the authentication flow by redirecting users to Auth0’s login page.
Usage:
Flow diagram:
/auth/callback
Handles the OAuth callback after successful authentication.
Flow:
- Validates the
stateparameter against stored transaction - Exchanges authorization code for tokens
- Validates ID token (signature, nonce, expiration)
- Creates encrypted session
- Redirects to
returnToor default path
onCallback hook (if configured) or returns a 500 error:
/auth/logout
Ends the user’s session and redirects to Auth0’s logout endpoint.
Usage:
Logout strategies:
The SDK supports three logout strategies:
Logout flow:
For OIDC logout, the SDK can optionally exclude See OIDC Logout Privacy Configuration for details.
id_token_hint for privacy:/auth/profile
Returns the current user’s profile from the session.
Response when authenticated:
- Default:
401 Unauthorizedwith empty body - With
noContentProfileResponseWhenUnauthenticated: true:204 No Content
useUser() hook fetches from this route:
The profile route returns user data from the ID token claims stored in the session. It does not make additional API calls to Auth0. To get fresh user data, use the Management API or re-authenticate the user.
/auth/access-token
Returns an access token for calling external APIs. Automatically refreshes expired tokens if a refresh token is available.
Response:
Client-side usage:
/auth/backchannel-logout
Handles back-channel logout requests from Auth0. This allows Auth0 to notify your application when a user’s session should be terminated.
Requirements:
- Stateful session storage (database-backed)
- Session store must implement
deleteByLogoutToken()method - Route must be configured in Auth0 Dashboard
Back-channel logout is only available with stateful sessions. Cookie-based (stateless) sessions cannot be revoked server-side. To learn more, see Back-Channel Logout documentation.
Custom Route Configuration
You can customize the route paths:Proxy Routes (My Account & My Organization APIs)
The SDK provides two additional proxy routes for Auth0’s My Account and My Organization Management APIs:/me/* - My Account API Proxy
Proxies requests to Auth0’s My Account API (https://{domain}/me/v1/*):
/my-org/* - My Organization API Proxy
Proxies requests to Auth0’s My Organization API (https://{domain}/my-org/*):
- Tokens remain on the server
- Automatic token refresh
- DPoP support for enhanced security
- No CORS issues
Learn more about Proxy Handler for My Account and My Organization APIs.
Route Protection
By default, authentication routes are public. To protect your application routes:Middleware Approach
Helper Methods
Server Components:Base Path Support
If your Next.js app uses a base path, set theNEXT_PUBLIC_BASE_PATH environment variable:
/dashboard/auth/login, /dashboard/auth/callback, etc.
Do not use
APP_BASE_URL with a path component when using NEXT_PUBLIC_BASE_PATH. Set APP_BASE_URL to the root domain only.Route Security Considerations
- Always use HTTPS in production - Authentication routes transmit sensitive data
- Validate redirect URLs - The SDK validates
returnToagainst allowed URLs - Register callback URLs - Add all callback URLs to Auth0 Dashboard
- Use SameSite cookies - Prevents CSRF attacks (enabled by default)
- Implement CSRF protection - The SDK uses
stateparameter for CSRF protection - Monitor authentication errors - Log errors from
onCallbackhook - Rate limit auth routes - Protect against brute force attacks
Next Steps
- Understand the Authentication Flow that powers these routes
- Configure Session Management for your needs
- Explore Custom Route Configuration