# Re fetching idtoken

**URL:** <https://community.auth0.com/t/re-fetching-idtoken/114982>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [August 29, 2023, 5:52pm UTC](https://community.auth0.com/t/re-fetching-idtoken/114982 "2023-08-29T17:52:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![auth0rocks](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/auth0rocks/32/50004_2.png) [@auth0rocks](https://community.auth0.com/u/auth0rocks)\
**Post date:** [August 29, 2023, 5:52pm UTC](https://community.auth0.com/t/re-fetching-idtoken/114982/1 "2023-08-29T17:52:46Z")

</div>

Hi

I fetch idtoken for login using

```auto
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.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 29, 2023, 11:30pm UTC](https://community.auth0.com/t/re-fetching-idtoken/114982/3 "2023-08-29T23:30:40Z")

</div>

Hey @auth0rocks ! 🤘

> [@auth0rocks](#):
>
> Is there anyway to fetch a freshly minted idtoken by re invoking getIdTokenClaims or do I need to logout and back in?

This should be possible by calling [getAccessTokenSilently](https://auth0.github.io/auth0-react/interfaces/Auth0ContextInterface.html#getAccessTokenSilently) and passing the [cacheMode param](https://auth0.github.io/auth0-react/interfaces/GetTokenSilentlyOptions.html#cacheMode) `{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!

---

<div class="post-metadata">

**Author:** ![auth0rocks](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/auth0rocks/32/50004_2.png) [@auth0rocks](https://community.auth0.com/u/auth0rocks)\
**Post date:** [August 31, 2023, 1:04am UTC](https://community.auth0.com/t/re-fetching-idtoken/114982/4 "2023-08-31T01:04:08Z")

</div>

It worked beautifully, thank you!

```auto
const { id_token } = await getAccessTokenSilently({
      cacheMode: 'off',
      detailedResponse: true,
    });
    return id_token;

```

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 31, 2023, 5:37pm UTC](https://community.auth0.com/t/re-fetching-idtoken/114982/5 "2023-08-31T17:37:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![auth0rocks](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/auth0rocks/32/50004_2.png) [@auth0rocks](https://community.auth0.com/u/auth0rocks)\
**Post date:** [August 31, 2023, 6:20pm UTC](https://community.auth0.com/t/re-fetching-idtoken/114982/6 "2023-08-31T18:20:46Z")

</div>

np

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 14, 2023, 6:21pm UTC](https://community.auth0.com/t/re-fetching-idtoken/114982/7 "2023-09-14T18:21:37Z")

</div>

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