How to fetch new token after updating user_metadata in React

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

e.g.

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

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

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

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