Cannot access user_metadata from Auth0Provider object

I wasn’t able to find a solution here or elsewhere:

  • My React app is wrapped in the Auth0Provider from @auth0/auth0-react.
  • I have an auth0 object in props with keys such as ‘error’, 'getAccessTokenSilently, ‘isAuthenticated’, ‘isLoading’… etc. including my ‘user’ object.
  • The user object contains the usual keys (email, name, nickname…etc), but NOT the user_metadata as I expect after setting a rule to do so.
  • The rule I have set is:
function (user, context, callback) {
  user.user_metadata = user.user_metadata || {};
  context.idToken[`user_metadata`] = user.user_metadata;
  callback(null, user, context);
}

I want to be able to call this.props.auth0.user.user_metadata from my app as I can with the other key values from the user object that persist.

Thanks in advance for any help.

Hi @ryanbuckleyca,

If you want to add custom claims to the token (like user_metadata), you must use a namespace that will not conflict with standard claims. For this you will use something that resembles a non-auth0 uri.

Take a look at this example:

1 Like

Thank you, that was it!

1 Like

Glad that solved it!

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