# Reflect the user\_metadata updates in real-time in React

**URL:** <https://community.auth0.com/t/reflect-the-user-metadata-updates-in-real-time-in-react/74722>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [December 13, 2021, 2:04pm UTC](https://community.auth0.com/t/reflect-the-user-metadata-updates-in-real-time-in-react/74722 "2021-12-13T14:04:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/skia/32/33713_2.png) [@Skia](https://community.auth0.com/u/Skia)\
**Post date:** [December 13, 2021, 2:04pm UTC](https://community.auth0.com/t/reflect-the-user-metadata-updates-in-real-time-in-react/74722/1 "2021-12-13T14:04:24Z")

</div>

Hello,

I apologize if this question has been answered before

I’m new to Auth0 and I happened to implement it in my newly created React application and after a couple of reads through the docs I managed to figure out how to update the user\_metadata through the client

My only issue is that the changes are not being reflected on the screen unless I manually refresh the page

Does anybody have an idea where I could’ve messed up?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 13, 2021, 6:18pm UTC](https://community.auth0.com/t/reflect-the-user-metadata-updates-in-real-time-in-react/74722/3 "2021-12-13T18:18:10Z")

</div>

Hi @Skia,

Welcome to the Auth0 Community!

How are you getting the metadata to the screen? Are you getting it from the token?

---

<div class="post-metadata">

**Author:** ![Skia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/skia/32/33713_2.png) [@Skia](https://community.auth0.com/u/Skia)\
**Post date:** [December 13, 2021, 6:57pm UTC](https://community.auth0.com/t/reflect-the-user-metadata-updates-in-real-time-in-react/74722/4 "2021-12-13T18:57:18Z")

</div>

Hello @dan.woda,

Thank you for getting back to me

I think i managed to solve it by implementing these 2 functions on the fly (it needs a lot of clean up, i’m aware haha) - I was just trying to make it work at a bare minimum level before i polish it

This is how i’m fetching the user\_metadata

```auto
 useEffect(() => {
    const getUserMetadata = async () => {
      const domain = "##########";

      try {
        const accessToken = await getAccessTokenSilently({
          audience: `https://${domain}/api/v2/`,
          scope: "read:current_user",
          ignoreCache: true,
        });

        const userDetailsByIdUrl = `https://${domain}/api/v2/users/${user.sub}`;

        const metadataResponse = await fetch(userDetailsByIdUrl, {
          headers: {
            Authorization: `Bearer ${accessToken}`,
          },
        });

        const { user_metadata } = await metadataResponse.json();

        setUserMetadata(user_metadata);
      } catch (e) {
        console.log(e.message);
      }
    };

    getUserMetadata();
  }, [getAccessTokenSilently, user]);

```

And this is how i’m updating the user\_metadata

```auto
 const updateUserMetadata = async () => {
    const domain = "##########";

    try {
      const accessToken = await getAccessTokenSilently({
        audience: `https://${domain}/api/v2/`,
        scope: "update:current_user_metadata",
        ignoreCache: true,
      });

      const userDetailsByIdUrl = `https://${domain}/api/v2/users/${user.sub}`;

      const { user_metadata } = await (
        await fetch(userDetailsByIdUrl, {
          method: "PATCH",
          headers: {
            Authorization: `Bearer ${accessToken}`,
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            user_metadata: { testData: "testData" },
          }),
        })
      ).json();
 
      setUserMetadata(user_metadata);
    } catch (e) {
      console.log(e.message);
    }
  };

```

I’m not really sure if there is a better way to go about it  
Am i making use of the getAccessTokenSilently function properly?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 13, 2021, 7:17pm UTC](https://community.auth0.com/t/reflect-the-user-metadata-updates-in-real-time-in-react/74722/5 "2021-12-13T19:17:50Z")

</div>

This looks like a valid solution. There are other ways to get metadata, but this would be a good way if you need the most up-to-date version of the metadata.

---

<div class="post-metadata">

**Author:** ![Skia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/skia/32/33713_2.png) [@Skia](https://community.auth0.com/u/Skia)\
**Post date:** [December 13, 2021, 7:58pm UTC](https://community.auth0.com/t/reflect-the-user-metadata-updates-in-real-time-in-react/74722/6 "2021-12-13T19:58:36Z")

</div>

@dan.woda thank you for your response

Would you please point me towards where i can read more about how to fetch metadata in other ways?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 13, 2021, 8:06pm UTC](https://community.auth0.com/t/reflect-the-user-metadata-updates-in-real-time-in-react/74722/7 "2021-12-13T20:06:39Z")

</div>

> **[Understand How Metadata Works in User Profiles](https://auth0.com/docs/manage-users/user-accounts/metadata)**
>
> Describes Auth0 user, application, and client metadata. Learn how you can use metadata to store information that does not originate from an identity provider.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 8, 2022, 4:27pm UTC](https://community.auth0.com/t/reflect-the-user-metadata-updates-in-real-time-in-react/74722/8 "2022-04-08T16:27:45Z")

</div>


