Greetings, I have just gone through the following tutorial to get my Next.js App integrated with Auth0.
I am able to log in and log out just fine but when trying to display user information on the page after login, the user is always null. I have made sure to follow every step in the tutorial exactly and the page that I am trying to display user data on looks like this:
import { useUser } from "@auth0/nextjs-auth0";
import Layout from "../components/layout";
export default function Profile({ ...props }) {
const { user, error, isLoading } = useUser();
if (isLoading) return <div>Loading...</div>;
if (error) return <div>{error.message}</div>;
if (user) {
return (
<Layout>
<div>
Welcome {user.name}! <a href="my-site/api/auth/logout">Logout</a>
</div>
</Layout>
)
}
return <a href="/api/auth/login" className="secondary-navbar-btn">Login</a>;
}
Again, I can log in through Auth0 just fine, but cant get the user object to return properly. After further inspection I noticed that I get an error in the browser console that reads: Failed to Load Resource ... 404 Not Found: http://localhost:3000/api/auth/me.
From my understanding, this url is related to getting the user’s profile. What can I do to fix this?
I’m not super familiar with this particular SDK/blog (they’re on my list!) so it’s tough to know exactly what could be going on here - I can however confirm that the sample app that is a companion to our Next.js SDK Quickstart documentation functions as expected. I am able to authenticate a user and utilize another route to display profile information. Perhaps you could give that a look?
For reference, both the quickstart and sample app can be found here:
Hi @tyf thank you for your response!
The tutorial you linked was actually the first tutorial I used to configure Auth0 in to my app.
I have triple checked my .env.local, my application settings on mange.auth0.com, and the profile.js file that returns the user object. I also went through the sample application’s repo and used the same profile.js that they used.
The same thing keeps happening though, after I log in, I get errors in the browser console saying that the user object cannot be returned and that the https://localhost:3000/api/auth/me url cannot be found.
I am willing to schedule a quick zoom call so that we can take a closer look at what is going on!
Hey @wisenickel5 thanks for the detailed information, just getting around to this!
I am leaning this way as well - Have you tested the sample app without setting a basePath? Regardless, looking here and here, what happens if you set NEXT_PUBLIC_AUTH0_PROFILE in your .env.local file to NEXT_PUBLIC_AUTH0_PROFILE="/my_path/api/auth/me"
Like I said I’m not super familiar with Next.js nor this SDK, but I think you’re on the right path!
I’m right there with you That’s entirely new to me… I’m super happy to know that did the trick for you - Thanks for your perseverance and for sharing with the community!