Preventing console errors when calling useUser() when user isn't logged in?

I’ve got my nextjs app up and running with the nextjs-auth0 SDK, including route protection and RBAC validation on the client.

I have pages users are allowed to view when not logged in, and I conditionally show UI based on that state by calling useUser() and seeing if I get a user back. However, every useUser() call made when the user isn’t logged in results in an error in the browser console:

        GET http://localhost:3000/auth/profile 401 (Unauthorized)

I see someone opened an issue about this in… 2022. Is it still really the only way to check for a logged in user?

1 Like

I’m having the same issue and also struggling to handle permission check on client side

Same issue here, and it’s baffling to me. How is it a good idea to throw console errors if someone simply isn’t logged in?

Can someone on the Auth0 team please advise how we’re supposed to properly check for authentication in NextJS? If useUser is the only way, and there’s no way around these console errors, then I think Auth0 needs to rethink its NextJS support.