When I look to see what initiates the call, its the use-user.js hook within the Auth0 code. This is the code:
"use client";
import useSWR from "swr";
export function useUser() {
const { data, error, isLoading } = useSWR(process.env.NEXT_PUBLIC_PROFILE_ROUTE || "/auth/profile", (...args) => fetch(...args).then((res) => {
if (!res.ok) {
throw new Error("Unauthorized");
}
return res.json();
}));
// if we have the user loaded via the provider, return it
if (data) {
return {
user: data,
isLoading: false,
error: null
};
}
if (error) {
return {
user: null,
isLoading: false,
error
};
}
return {
user: data,
isLoading,
error
};
}
When I’m logged in it’s not really a problem. But when I’m not, it clogs up my logs with a 404 error. Is this expected behavior? The only thing I can think of is I set up my middleware wrong, but I followed the quick start.
I am sorry about the delayed response to your inquiry!
Basically, if an user is not authenticated in your NextJS application, it should not be throwing 404 errors continually.
Are you redirecting to a proper auth endpoint as mentioned in this community post? Also, are you using loginWithRedirect() or loginWithPopup()? You could try to download our sample app and build upon it or replace parts and see if the behaviour is being reproduced.
Simply, I believe there might be a slight misconfiguration inside your application where it is not using a proper endpoint. You could examine the sample application and compare it with your own personal configuration.
I’m not using loginWithRedirect() or loginWithPopup(). I’m I have a button that takes users to http://localhost:3000/auth/login. That works fine. And I double checked my settings and confirmed localhost is included where possible:
It’s just the profile endpoint that keeps triggering which I don’t have anywhere in my code. I looked at the link you gave but I don’t see a mention of using a proper endpoint vs an improper one…am I missing something? I also dont see a sample app to clone. The link in your docs HERE is broken
We’re also seeing the /auth/profile endpoint being called every few seconds in our Next application running SDK v4.9.0. We tested with the official sample app as @nik.baleca suggested and observed the same behavior.
It sounds like this isn’t expected behavior, did you find out if there’s a way to configure/disable it @mmaccou?