isAuthenticated remains false and user is undefined after successful login callback #820
Open
6 tasks done
Labels
bug
Something isn't working
Checklist
Description
Description
I am experiencing an issue where the
isAuthenticated
property from the@auth0/auth0-react
library remainsfalse
, even though the login process seems to succeed, and I am redirected back to the callback URL with a validcode
parameter. Additionally, theuser
property isundefined
, and no token is being saved tolocalStorage
.I expected the
isAuthenticated
property to betrue
, theuser
property to contain user information, and a token to be retrievable viagetAccessTokenSilently()
. However, none of these expectations are being met, and my application is stuck in a loop trying to handle authentication.Steps Taken:
Verified that the
Auth0Provider
is configured correctly:domain
,clientId
,redirect_uri
, andaudience
are set using environment variables.onRedirectCallback
function is defined but not being called.Ensured the following configurations are correct in the Auth0 dashboard:
Allowed Callback URLs
:http://localhost:5173/auth/callback
Allowed Web Origins
:http://localhost:5173
Confirmed that the URL includes the
code
andstate
parameters after login:http://localhost:5173/auth/callback?code=...&state=...
.Added detailed logs in
onRedirectCallback
and inside thegetAccessTokenSilently()
method:onRedirectCallback
is not being triggered.getAccessTokenSilently()
is not returning a token, and no errors are logged in thecatch
block.Tested with
loginWithRedirect
to force login, butisAuthenticated
remainsfalse
.Checked that the Auth0 application uses the
Authorization Code Flow with PKCE
.Despite these efforts, the issue persists. Any guidance or insights into resolving this would be appreciated.
Reproduction
Reproduction
This issue can be consistently reproduced by following these steps:
Set up an Auth0 application with the following configuration:
http://localhost:5173/auth/callback
http://localhost:5173
Use the
@auth0/auth0-react
library in a React project with the following setup:Auth0Provider
:redirect_uri
points to/auth/callback
.Implement the callback handling with the
useAuth0
hook:Run the application locally on
http://localhost:5173
.Log in via the Auth0-hosted login page:
http://localhost:5173/auth/callback
with a validcode
andstate
.Observed Behavior:
isAuthenticated
remainsfalse
.user
object isundefined
.getAccessTokenSilently
method does not return a token or throw an error.localStorage
.Expected Behavior:
isAuthenticated
should betrue
.user
object should contain user information.localStorage
.Additional context
No response
auth0-react version
2.2.4
React version
18.2.0
Which browsers have you tested in?
Chrome, Firefox
The text was updated successfully, but these errors were encountered: