isAuthenticated of useAuth0 is too slow, why?
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was able to identify the cause of the problem. It seems that the problem was that I was calling
getAccessTokenSilently()
beforeisAuthenticated
becametrue
. I apologize for the inconvenience.@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
beforeisAuthenticated
wastrue
it went away.