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?
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;
};
Hey there!
Can you open this as a GitHub issue in our react repo so we can get that addressed directly with the SDK maintainers? Once you have a link to it please share it here so we can ping them. Thank you!
I’ve created an Issue here.
opened 12:39PM - 29 Oct 21 UTC
closed 03:51PM - 29 Oct 21 UTC
### 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
```tsx
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
Perfect! I’ll ping them in a minute!
system
Closed
November 13, 2021, 12:41pm
5
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.