Hey,
Currently, I’m working on react application where I have integrated auth0 login/signup but failed to login in the Incognito window in google chrome.
Getting errors like login_required
- Tried
useRefreshTokens
too but in that scenario getting aRefresh token missing
error.
Here is information about SDK I’m using:
- SDK name - “@auth0/auth0-react”
- SDK Version - “^2.2.0”
- react - “^18.2.0”
Here’s the implementation
<Auth0Provider
domain={getAuth0Creds().domain}
clientId={getAuth0Creds().clientId}
authorizationParams={{
redirect_uri: window.location.origin,
connection: 'email',
scope: getAuth0Creds().scope
}}
>
<ApolloProvider client={apolloClient}>
<CustomContexts>
<BrowserRouter>
<RoutesMain />
</BrowserRouter>
</CustomContexts>
</ApolloProvider>
</Auth0Provider>
And using these methods in routes file
const { getIdTokenClaims, getAccessTokenSilently, isAuthenticated } =
useAuth0();
useEffect(() => {
const getToken = async () => {
try {
await getAccessTokenSilently();
const idToken = await getIdTokenClaims();
if (idToken) {
localStorage.setItem('ACCESSTOKEN', JSON.stringify(idToken?.__raw));
}
} catch (error) {
if (!isAuthenticated && error) {
navigate(PATH.AUTH, { replace: true });
}
}
};
void getToken();
}, [getAccessTokenSilently, getIdTokenClaims, isAuthenticated]);