Skip to main content
The Auth0 Next.js SDK automatically mounts 6 authentication routes that handle the complete authentication lifecycle. These routes are processed by the SDK’s middleware (Next.js 15) or proxy (Next.js 16).

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:
Query Parameters: Flow diagram:
The returnTo URL must be registered in your Auth0 Application’s Allowed Callback URLs. The SDK validates the URL against this list for security.

/auth/callback

Handles the OAuth callback after successful authentication. Flow:
  1. Validates the state parameter against stored transaction
  2. Exchanges authorization code for tokens
  3. Validates ID token (signature, nonce, expiration)
  4. Creates encrypted session
  5. Redirects to returnTo or default path
Error handling: If authentication fails, the SDK calls the onCallback hook (if configured) or returns a 500 error:
This route must be registered in your Auth0 Application’s Allowed Callback URLs. The default URL is http://localhost:3000/auth/callback for development.

/auth/logout

Ends the user’s session and redirects to Auth0’s logout endpoint. Usage:
Query Parameters: Logout strategies: The SDK supports three logout strategies:
Logout flow:
The returnTo URL must be registered in your Auth0 Application’s Allowed Logout URLs.
For OIDC logout, the SDK can optionally exclude id_token_hint for privacy:
See OIDC Logout Privacy Configuration for details.

/auth/profile

Returns the current user’s profile from the session. Response when authenticated:
Response when not authenticated:
  • Default: 401 Unauthorized with empty body
  • With noContentProfileResponseWhenUnauthenticated: true: 204 No Content
Client-side usage: The 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:
Query Parameters: Client-side usage:
Automatic token refresh: Configuration:
This route is enabled by default but should only be used when access tokens are needed client-side. For server-side API calls, use auth0.getAccessToken() directly to avoid unnecessary network requests.

/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:
  1. Stateful session storage (database-backed)
  2. Session store must implement deleteByLogoutToken() method
  3. Route must be configured in Auth0 Dashboard
Implementation:
Flow:
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:
If you customize routes, you must update the Allowed Callback URLs and Allowed Logout URLs in your Auth0 Application settings to match the new 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/*):
How it works: Benefits:
  • Tokens remain on the server
  • Automatic token refresh
  • DPoP support for enhanced security
  • No CORS issues

Route Protection

By default, authentication routes are public. To protect your application routes:

Middleware Approach

Helper Methods

Server Components:
Client Components:
API Routes:

Base Path Support

If your Next.js app uses a base path, set the NEXT_PUBLIC_BASE_PATH environment variable:
The SDK will mount routes at /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

  1. Always use HTTPS in production - Authentication routes transmit sensitive data
  2. Validate redirect URLs - The SDK validates returnTo against allowed URLs
  3. Register callback URLs - Add all callback URLs to Auth0 Dashboard
  4. Use SameSite cookies - Prevents CSRF attacks (enabled by default)
  5. Implement CSRF protection - The SDK uses state parameter for CSRF protection
  6. Monitor authentication errors - Log errors from onCallback hook
  7. Rate limit auth routes - Protect against brute force attacks

Next Steps