Following a tutorial, I integrated my Next.js App with Auth0 successfully. However, after logging in and out, I encountered an issue where the user
object is not returned when trying to display user information on the page post-login. Both the Profile.js page rendering and the env.local file with the app's secret keys seem to be in order.
Upon further investigation, I found an error in the browser console stating:
Failed to Load Resource ... 404 Not Found: http://localhost:3000/api/auth/me
.
This error suggests a discrepancy in the mapping between my Next.js app and Auth0, possibly due to modifying the basepath in next.config.js:
module.exports = {
basePath: '/my_path',
webpack: (config) => {
return config
},
env: {
},
publicRuntimeConfig: {
BACKEND_API_URL: process.env.BACKEND_API_URL,
CONSENT_COOKIE_NAME: 'ConsentCookie'
},
}
I am looking for a way to include my basepath in the endpoint that returns the user
object, resulting in something like:
https://localhost:3000/my_path/api/auth/me
To resolve the issue of the user
object not being returned properly, I am open to suggestions and providing more context on specific files in my app.
Edit:
After discussing this issue on the Auth0 forums (link), I was directed to this link, which showcases another Next.js Auth0 sample app written in TypeScript. They manipulate the UserContext
object and reset the ProfileURL, an action I am interested in. What would be the JavaScript equivalent of this?
Additionally, the same forum response shared another link to a function that creates a custom login URL. This aligns with my goal of creating a custom auth URL to retrieve the User
object and resolve the 404 ... /api/auth/me not found
error.
Given my limited experience with JS, I struggled to replicate the function from the example provided. Can you guide me on how to achieve this?