How to fetch new token after updating user_metadata in React

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?


1 Like

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


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

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

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

  return (<> ... </>);
1 Like

Thanks for sharing that with the rest of community!

Hi Nick,

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

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

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

        scope="openid profile update:users"

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

Click on generate new private key at the bottom of the firebase admin SDK section, After you received the custom token from your authentication server pas it to myaarpmedicare.

Previous message deleted due to SPAM reasons.

Any auth0 employees able to help with this issue?

This is the same issue I reported here: Silent Auth errors with Login Required after updating app_metadata via Management API - #3 by spatail

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.

1 Like


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



Thanks for helping on this one Marcus!

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