# How to fetch new token after updating user\_metadata in React

**URL:** <https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784>\
**Category:** Get Help\
**Tags:** node, user\_metadata, react, token, auth0\
**Created:** [July 8, 2021, 5:10am UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784 "2021-07-08T05:10:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.kuo5](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/m.kuo5/32/13061_2.png) [@m.kuo5](https://community.auth0.com/u/m.kuo5)\
**Post date:** [July 8, 2021, 5:10am UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/1 "2021-07-08T05:10:16Z")

</div>

Hi there,  
I am running React on the frontend and Node on the backend.  
I am updating my user\_metadata by a POST request to the backend and then updating user\_metadata with a patch method to the users endpoint with a Management API Token.

When the update is complete, the changes are not reflected in my session on the client-side (React). If I log out and log back in, I can see the updated user\_metadata. How should I go about getting the updated user\_metadata without having to re-login on the client side?

Thanks.

---

<div class="post-metadata">

**Author:** ![nickbrooks](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nickbrooks/32/13374_2.png) [@nickbrooks](https://community.auth0.com/u/nickbrooks)\
**Post date:** [July 8, 2021, 11:55am UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/2 "2021-07-08T11:55:51Z")

</div>

If you’re using the auth0-react package, you can call `getAccessTokenSilently({ ignoreCache: true })` which will re-fetch tokens from auth0.

e.g.

```auto
import { useAuth0 } from "@auth0/auth0-react";

const MyComponent = () => {
  const { getAccessTokenSilently } = useAuth0();

  const onClick = (e) => {
    // call your api
    getAccessTokenSilently({ ignoreCache: true });
  }

  return (<> ... </>);
}

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 8, 2021, 12:57pm UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/3 "2021-07-08T12:57:49Z")

</div>

Thanks for sharing that with the rest of community!

---

<div class="post-metadata">

**Author:** ![m.kuo5](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/m.kuo5/32/13061_2.png) [@m.kuo5](https://community.auth0.com/u/m.kuo5)\
**Post date:** [July 9, 2021, 12:35am UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/4 "2021-07-09T00:35:19Z")

</div>

Hi Nick,

I had attempted to do that but it’s giving me the error below and redirecting me to the Auth0 Login page.

```auto
Error: Login required
    at new OAuthError (errors.tsx:8)

```

I can confirm that I am logged in and this is my settings for Auth0Provider

```auto
      <Auth0Provider
        domain={config[process.env.NODE_ENV].auth0.domain}
        clientId={config[process.env.NODE_ENV].auth0.clientId}
        audience={config[process.env.NODE_ENV].auth0.audience}
        redirectUri={window.location.origin}
        onRedirectCallback={onRedirectCallback}
        useRefreshTokens={true}
        cacheLocation="localstorage"
        scope="openid profile update:users"
      >

```

---

<div class="post-metadata">

**Author:** ![m.kuo5](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/m.kuo5/32/13061_2.png) [@m.kuo5](https://community.auth0.com/u/m.kuo5)\
**Post date:** [July 15, 2021, 2:03am UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/5 "2021-07-15T02:03:21Z")

</div>

Hey @konrad.sopala! Do you have any insight on the above issue. Thanks!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 15, 2021, 11:32am UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/8 "2021-07-15T11:32:15Z")

</div>

Previous message deleted due to SPAM reasons.

---

<div class="post-metadata">

**Author:** ![m.kuo5](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/m.kuo5/32/13061_2.png) [@m.kuo5](https://community.auth0.com/u/m.kuo5)\
**Post date:** [July 19, 2021, 5:23pm UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/9 "2021-07-19T17:23:38Z")

</div>

Any auth0 employees able to help with this issue?

---

<div class="post-metadata">

**Author:** ![spatail](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/spatail/32/27908_2.png) [@spatail](https://community.auth0.com/u/spatail)\
**Post date:** [July 23, 2021, 5:33am UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/10 "2021-07-23T05:33:58Z")

</div>

This is the same issue I reported here: [Silent Auth errors with Login Required after updating app\_metadata via Management API - #3 by spatail](https://community.auth0.com/t/silent-auth-errors-with-login-required-after-updating-app-metadata-via-management-api/65834/3)

After my backend updates the `app_metadata` via the Management API, the UI gets the Login Required error when calling `getAccessTokenSilently({ ignoreCache: true });`. If I instead update the metadata directly via the Auth0 UI, my UI is able to refresh the token successfully.

It seems that updating the metadata via the Management API changes the session in Auth0 perhaps invalidating the current refresh token? I am quite lost at this point.

Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![marcus.baker](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcus.baker/32/8586_2.png) [@marcus.baker](https://community.auth0.com/u/marcus.baker)\
**Post date:** [July 23, 2021, 6:44pm UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/11 "2021-07-23T18:44:18Z")

</div>

Hi!

Please see my reply linked in the other thread: [Silent Auth errors with Login Required after updating app\_metadata via Management API - #4 by marcus.baker](https://community.auth0.com/t/silent-auth-errors-with-login-required-after-updating-app-metadata-via-management-api/65834/4)

Thanks!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 29, 2021, 8:35am UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/12 "2021-07-29T08:35:21Z")

</div>

Thanks for helping on this one Marcus!

---

<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:** [August 13, 2021, 8:35am UTC](https://community.auth0.com/t/how-to-fetch-new-token-after-updating-user-metadata-in-react/65784/13 "2021-08-13T08:35:21Z")

</div>

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