I was setting cacheLocation as authorizationParams instead at Auth0Provider level. After moving that value to it Auth0Provider, I can see local storage is getting populated with the information.
const authorizationParams = {
scope: scope,
redirect_uri: redirectUri,
audience: audience,
connection: connectionId
};
return (
<Auth0Provider
domain={domain}
clientId={clientId}
cacheLocation="localstorage"
cache={customStorageCache}
useRefreshTokens={true}
onRedirectCallback={onRedirectCallback}
authorizationParams={authorizationParams} >
{children}
</Auth0Provider>
);
On refresh it was navigating to login screen even refreshToken is enabled. I have to add isLoading check to app.tsx file and auto login only when isAuthenticated is not true. It took care of redirecting to “loginWithRedirect → returnTo” page.
It will be helpful, if someone is having issues.
const { isLoading } = useAuth0();
return (
<>
{isLoading && (
<div className="page-layout">
<PageLoader />
</div>
)}
{!isLoading && (
<Routes>
<Route
path="/"
element={<Home />} />
<Route
path="/home"
element={<Home />} />
<Route
path="/callback"
element={<CallbackPage />} />
<Route
path="/protected"
element={<AuthenticationGuard component={MyProtectedPage} />}
/>
<Route
path="*"
element={<NotFoundPage />} />
</Routes>
)}
</>
);