Next.js Callback 404 Not Found Error
Last Updated:
Overview
This article explains why a 404 Not Found error may be seen on the /api/auth/callback route when utilizing the nextjs-auth0 library.
Applies To
- NextJS-Auth0
Cause
If the callback looks similar to the following error, with <AUTH0-DOMAIN> being the domain associated with the Auth0 tenant, this error is happening because of the misuse of the Auth0 domain.
https://<AUTH0-DOMAIN>/api/auth/callback
- The Auth0 domain should only be utilized to complete calls towards one of the Auth0-managed APIs
- The error occurs because the /api/auth/callback is not an Auth0 API endpoint, but rather a route in the application.
Solution
- Verify that the environment variable
AUTH0_BASE_URLexists within the .env configuration file for applications built with the NextJS-Auth0 SDK. - Set the
AUTH0_BASE_URLvariable to the base URL where the Next.js application is hosted.- For local development, this value is typically similar to the following example:
http://localhost:3000.
- For local development, this value is typically similar to the following example:
- Confirm the
AUTH0_BASE_URLvariable contains the application's hosting URL, not the Auth0 tenant domain.- Example of an incorrect value (tenant domain):
https://<tenant_name>.<region>.auth0.com/
- Example of an incorrect value (tenant domain):
- If issues continue, check the configured
AUTH0_BASE_URLdomain for correct spelling and validity.