getAccessTokenSilently throws error login required

I am using latest auth0-react lib. After user logs in using universal login and database connection, getAccessTokenSilently, this trows error Login required. Everything works in chrome incognito mode. Same errors is Safari, Safari incognito mode. Seems to be related to cookies being blocked. It might be solved by using custom domain, are the solution for default auth0 domains? + Login Required seems to be confusing message in this case.

1 Like

Did you get any responses? I am facing similar problem.

I am having the same issue. getAccessTokenSilently works in chrome and firefox

It seems like the others on this thread are having configuration issues. For anyone who is like me and winding up here to figure out what is going on with this error, I wanted to share what I found:

  1. Both login_required and consent_required are legitimate opened responses. They seem to arise out of inactivity timeouts and needing more permissions respectively. (more info here: https://openid.net/specs/openid-connect-core-1_0.html#AuthError)
  2. As such, when you use getAccessTokenSilently, you pretty much always need to wrap it in a try...catch and look for these errors, a la:
    try {
      token = await getAccessTokenSilently();
    } catch (e) {
      if (e.error === 'login_required') {
        loginWithRedirect();
      }
      if (e.error === 'consent_required') {
        loginWithRedirect();
      }
      throw e;
    }

The quick start doesn’t really make mention of this, but it is in an example in the auth0-react repo, here: Code lifted from https://github.com/auth0/auth0-react/blob/master/EXAMPLES.md#4-create-a-useapi-hook-for-accessing-protected-apis-with-an-access-token

Hopefully, this helps someone who is chasing their tail.