question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

isAuthenticated of useAuth0 is too slow, why?

See original GitHub issue

Describe the problem

We are using @auth0/auth0-react in our React app. After login, it takes about 10 seconds for isAuthenticated of useAuth0 to become true. Why is it taking so long? Is there anything I can do to improve this?

ref: https://community.auth0.com/t/isauthenticated-of-useauth0-is-too-slow-why/72298

What was the expected behavior?

isAuthenticated should become true in about few second.

Reproduction

import { Loading } from '@/components/feedback/Loading';
import { useAuth0 } from '@auth0/auth0-react';
import React, { useContext, useEffect } from 'react';

export const LoginRestrictedRoute = ({ children }) => {
  const { isAuthenticated, isLoading, loginWithRedirect } = useAuth0();

  useEffect(() => {
    if (!isLoading && !isAuthenticated) {
     loginWithRedirect({
        appState: {
          targetUrl: window.location.href,
        },
      });
    }
  }, [isLoading, isAuthenticated]);

  if (isLoading || !isAuthenticated) {
    return <Loading loading={isLoading} size="large" />;
  }

  return children;
};

Environment

  • Which SDK this is regarding: @auth0/auth0-react

  • SDK Version: ^1.3.0

  • Platform Version: react: 17.0.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mikan3rdcommented, Oct 29, 2021

I was able to identify the cause of the problem. It seems that the problem was that I was calling getAccessTokenSilently() before isAuthenticated became true. I apologize for the inconvenience.

0reactions
michaelm244commented, Jun 7, 2022

@mikan3rd Thanks for posting the cause you found!

I had the exact same symptoms (random, unexplained loading) and once I removed the codepath that was calling getAccessTokenSilently before isAuthenticated was true it went away.

Read more comments on GitHub >

github_iconTop Results From Across the Web

isAuthenticated of useAuth0 is too slow, why?
We are using @auth0/auth0-react in our React app. After login, it takes about 10 seconds for isAuthenticated of useAuth0 to become true.
Read more >
How to mock Auth0 spa hooks to test your React components
In this tutorial, I'm assuming the below: you have some basic knowledge of what unit tests are, why they're useful, and you've done...
Read more >
Add Authentication to your React apps with Auth0 - Upmostly
To check if the user has authenticated we are using isAuthenticated boolean property again available in the useAuth0 hook. Now, import all the...
Read more >
Persistent login in React using refresh token rotation
In this tutorial, you can learn how to use refresh tokens in React to facilitate infinitely long login sessions.
Read more >
dansult's What Got Done for the week of 2021-12-17
User authenticated is done and the firewall rules pages have been ported ... isLoading, getAccessTokenSilently, } = useAuth0(); const {data, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found