Re fetching idtoken


I fetch idtoken for login using

const { getIdTokenClaims } = useAuth0();

 const innerClaims = await getIdTokenClaims();

but later in the flow I need to fetch a fresh idtoken since I need the post login action to rerun and populate token with some newly added app_metadata value (which happens after first login+ backend call). Is there anyway to fetch a freshly minted idtoken by re invoking getIdTokenClaims or do I need to logout and back in?

Also is an alternative to make an api call instead, to auth0, since I just need to get some app_metadata from the user record, that has been updated after first login attempt.

Hey @auth0rocks ! :metal:

This should be possible by calling getAccessTokenSilently and passing the cacheMode param {cacheMode: "off"}. This basically just forces the refreshing of tokens - Unfortunately I am not aware of any way to only get a new ID token, so this will also return a new access token.

Hope this helps!

It worked beautifully, thank you!

const { id_token } = await getAccessTokenSilently({
      cacheMode: 'off',
      detailedResponse: true,
    return id_token;
1 Like

That’s great to hear! Thanks for confirming with the community :slight_smile:


follow up

if I get a new idToken like this and the token claims have exp field in them, can I use them to decide if I need to get a new idToken? Or does the exp only apply to access tokens?

I am wondering I would beset handle expired idTokens in my app, I am using the idToken in my backend to extract app-metadata

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.