Hi there, I have a problem with integrating auth0 into my React application.
Everything is done like in the official demo example, but:
The authentification is successful but when I am trying to get {user} or {isAuthenticated} values from the useAuth0() it returns me “undefined” and “false” as well.
I’ve been testing the app for a couple of months without problem and now suddenly this has appeared. After going through the login procedure, the user is returned to my app but with isAuthenticated false. Pressing login again initiates isLoading, but there is no redirect to the Auth0 site. If the user closes the browser window (Chrome) and then reopens, the app now receives an IsAuthenticated from Auth0.
Yes,
The issue you’re describing could be caused by a few different things, but most likely it is related to the way you are using the Auth0-react library.
Make sure you have properly configured the Auth0Provider component in your application. This component should wrap your entire application and provide the necessary configuration options for the Auth0 SDK to work correctly. For example:
Check that you are calling the useAuth0 hook correctly in your components. This hook provides access to the user and isAuthenticated objects that you are trying to access. Make sure you are calling the hook inside a functional component and that you are using the destructured values correctly. For example:
Verify that the user has actually authenticated with Auth0. You can check this by looking at the localStorage object in your browser’s developer tools. Auth0 stores a JWT token in local storage when a user is authenticated. If you don’t see this token, it means the user has not yet authenticated. You may need to trigger the authentication flow by calling the loginWithRedirect function provided by the useAuth0 hook.
Just in case it’s useful, this happened to me in the past a few times and was related to the use of localhost instead of 127.0.0.1 (or custom domain) for development.
Said that, this last time, it started to happen was due to use the wrong scope in the authorizationParams for the Auth0Provider component.