isAuthenticated sometimes is false after successful OAuth login (Google)

Hello! I know there is a plenty of topics describing isAuthenticated bug but unfortunately none of the answers did help. We experience an issue with auth0-react which makes our app unusable. Sometimes after a successful login useAuth0 returns both isLoading and isAuthenticated to be true. My client and their colleagues use Chromium but I could reproduce it in Safari. error is always undefined. The code:

useEffect(() => {
    if (!isAuthenticated && !isLoading && !error) {
      void loginWithRedirect();
    }
  }, [error, isAuthenticated, isLoading, loginWithRedirect]);

As you can see we re-direct a user when the component is rendered which makes the app reload from 0 to around 20 times. After those weird re-loads we finally get isAuthenticated to be true.

This issue appears on version 1 as well as 2 of auth0-react. I tried different workarounds (wait for some time before calling loginWithRedirect, check if the NextJS router is ready) but nothing helped. I hope we’ll find a solution. Thank you in advance!

Update. That’s what auth0 logs show:

That’s what one of the latest logs give:

{
  "date": "2023-02-06T18:02:19.055Z",
  "type": "fsa",
  "description": "Login required",
  "client_id": "[EDITED]",
  "client_name": "[EDITED]",
  "ip": "[EDITED]",
  "user_agent": "Safari 16.2.0 / Mac OS X 10.15.7",
  "details": {
    "body": {},
    "qs": {
      "client_id": "[EDITED]",
      "scope": "openid profile email offline_access",
      "redirect_uri": "http://localhost:3000",
      "audience": "[EDITED]",
      "prompt": "none",
      "response_type": "code",
      "response_mode": "web_message",
      "state": "[EDITED]",
      "nonce": "[EDITED]",
      "code_challenge": "[EDITED]",
      "code_challenge_method": "S256",
      "auth0Client": "[EDITED]"
    },
    "connection": null,
    "error": {
      "message": "Login required",
      "oauthError": "login_required",
      "type": "oauth-authorization"
    },
    "riskAssessment": null
  },
  "hostname": "[EDITED]",
  "audience": "[EDITED]",
  "scope": [
    "openid",
    "profile",
    "email",
    "offline_access"
  ],
  "auth0_client": {
    "name": "auth0-react",
    "version": "2.0.0"
  },
  "log_id": "90020230206180224097178626835065049500894581052936290322",
  "_id": "90020230206180224097178626835065049500894581052936290322",
  "isMobile": false,
  "id": "90020230206180224097178626835065049500894581052936290322"
}

I hope this helps.

1 Like