Hi There,
I have a setup on using Single page application and I am using the “@auth0/auth0-react”, also enabled localstorage as cache location and useReferesToken is true. Whenever the user clicks on the submit button I am calling the getAccessTokenSilently method, but I am not getting the new token and the APIs are failing as the existing token already expired. Please help me here.
export const GetCurrentUserAccessToken = () => {
const { user, getAccessTokenSilently, getIdTokenClaims } = useAuth0();
useEffect(() => {
const getUserMetadata = async () => {
try {
if (currentUserToken == null) {
const accessToken = await getAccessTokenSilently({
useRefreshTokens: true
});
// console.log('accessToken ', accessToken, user);
userInfo = user;
currentUserToken = accessToken;
const idTokenClaims = await getIdTokenClaims();
if (idTokenClaims?.__raw) {
idtoken = idTokenClaims?.__raw;
}
}
} catch (e) {
console.log(e.message);
}
};
getUserMetadata();
}, [getAccessTokenSilently, user?.sub]);
return {currentUserToken, idtoken};
};