# Need help on getting idtoken user\_metadata with react-auth0-sdk

**URL:** <https://community.auth0.com/t/need-help-on-getting-idtoken-user-metadata-with-react-auth0-sdk/80740>\
**Category:** Get Help\
**Tags:** react-sdk, metadata\
**Created:** [March 29, 2022, 10:05pm UTC](https://community.auth0.com/t/need-help-on-getting-idtoken-user-metadata-with-react-auth0-sdk/80740 "2022-03-29T22:05:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dudumonteiro](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dudumonteiro/32/35891_2.png) [@dudumonteiro](https://community.auth0.com/u/dudumonteiro)\
**Post date:** [March 29, 2022, 10:05pm UTC](https://community.auth0.com/t/need-help-on-getting-idtoken-user-metadata-with-react-auth0-sdk/80740/1 "2022-03-29T22:05:53Z")

</div>

Hi there,

I attached some user metadata on an Auth0 action on Login, and I can see them correctly attached on Auth0 dashboard. Here’s how it appears there:

```auto
{
  "sub": "auth0|6237476d0f4b920069241ec6",
  "nickname": "admin",
  "name": "admin@example.com",
  "picture": "https://s.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fad.png",
  "updated_at": "2022-03-28T23:10:02.568Z",
  "https://dev-r3pn41if:us:auth0:com/organization": null,
  "https://dev-r3pn41if:us:auth0:com/position": null,
  "https://dev-r3pn41if:us:auth0:com/phone_number": null,
  "https://dev-r3pn41if:us:auth0:com/dummy": "dummyvalue"
}

```

But when I access user property from react sdk, I get only the stardard attributes (user\_metadata and app\_metadata does not appear).

Here’s how I get user property:

```javascript

const { user, getAccessTokenSilently, logout } = this.props.auth0;
console.log(user); // displays only 'standard' attibutes

```

My question is: how I get user\_metadata with react-auth0-sdk?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [March 30, 2022, 5:54pm UTC](https://community.auth0.com/t/need-help-on-getting-idtoken-user-metadata-with-react-auth0-sdk/80740/3 "2022-03-30T17:54:21Z")

</div>

Hi @dudumonteiro,

Thanks for reaching out to the Auth0 Community!

Once you have attached the user\_metadata to the ID Token using an Auth0 Post Login Action, you can use the `useAuth0` hook to call the `getIdTokenClaims` method to retrieve the custom claims.

For clarity, your Post Login Action script should look something like the following:

```auto
/**
 * @param {Event} event - Details about the user and the context in which they are logging in.
 * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
 */
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/user_metadata.fav_color`, event.user.user_metadata.fav_color); 
  }
}

```

Lastly, you may find the [https://auth0.github.io/auth0-react/modules/use\_auth0.html](https://auth0.github.io/auth0-react/modules/use_auth0.html) reference useful.

Please let me know if there’s anything else I can do to help.

Thank you.

---

<div class="post-metadata">

**Author:** ![dudumonteiro](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dudumonteiro/32/35891_2.png) [@dudumonteiro](https://community.auth0.com/u/dudumonteiro)\
**Post date:** [March 31, 2022, 12:06pm UTC](https://community.auth0.com/t/need-help-on-getting-idtoken-user-metadata-with-react-auth0-sdk/80740/4 "2022-03-31T12:06:13Z")

</div>

Hi @rueben.tiow !

Thank you for reply.

Unfortunately I’m still getting only standard attributes.  
I did your tip on login action and using `getIdTokenClaims`.

My login action:

```javascript
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://dev-r3pn41if.us.auth0.com';
  const { organization, position, phone_number } = event.user.user_metadata;

  if (event.authorization) {
    // Set claims 
    api.idToken.setCustomClaim(`${namespace}/user_metadata.organization`, organization);
    api.idToken.setCustomClaim(`${namespace}/user_metadata.position`, position);
    api.idToken.setCustomClaim(`${namespace}/user_metadata.phone_number`, phone_number);
    api.idToken.setCustomClaim(`${namespace}/user_metadata.dummy`, 'dummyvalue');
  }
};

```

My app:

```javascript
        // ...
        const { user, getAccessTokenSilently, getIdTokenClaims,logout } = this.props.auth0;
        let claims = await getIdTokenClaims();    
        console.log(claims); // displays only standard attributes

```

Here is what I get from auth0 dashboard:

```javascript
{
  "sub": "auth0|6237476d0f4b920069241ec6",
  "nickname": "admin",
  "name": "admin@example.com",
  "picture": "https://s.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fad.png",
  "updated_at": "2022-03-31T12:56:32.246Z",
  "https://dev-r3pn41if:us:auth0:com/user_metadata:organization": "turtle",
  "https://dev-r3pn41if:us:auth0:com/user_metadata:position": "biologist",
  "https://dev-r3pn41if:us:auth0:com/user_metadata:phone_number": "1000-1000",
  "https://dev-r3pn41if:us:auth0:com/user_metadata:dummy": "dummyvalue"
}

```

Here is what I get from console.log display:

```javascript
aud: "gAkDn9TJlEmDqsc62MYdCiNc2tVP0qLp"
email: "admin@example.com"
email_verified: false
exp: 1648765861
iat: 1648729861
iss: "https://dev-r3pn41if.us.auth0.com/"
name: "admin@example.com"
nickname: "admin"
nonce: "Mlc1OXVHTlFVZ1ExQjNxSWx2UmZySUh6MVJ0bW9sWmFYMklDeWRiR293TQ=="
picture: "https://s.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fad.png"
sub: "auth0|6237476d0f4b920069241ec6"
updated_at: "2022-03-31T12:22:23.277Z"
__raw: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImswVnVUMHRodmtYbG9yT25Eb0JuZiJ9.eyJuaWNrbmFtZSI6ImFkbWluIiwibmFtZSI6ImFkbWluQGV4YW1wbGUuY29tIiwicGljdHVyZSI6Imh0dHBzOi8vcy5ncmF2YXRhci5jb20vYXZhdGFyL2U2NGM3ZDg5ZjI2YmQxOTcyZWZhODU0ZDEzZDdkZDYxP3M9NDgwJnI9cGcmZD1odHRwcyUzQSUyRiUyRmNkbi5hdXRoMC5jb20lMkZhdmF0YXJzJTJGYWQucG5nIiwidXBkYXRlZF9hdCI6IjIwMjItMDMtMzFUMTI6MjI6MjMuMjc3WiIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5jb20iLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImlzcyI6Imh0dHBzOi8vZGV2LXIzcG40MWlmLnVzLmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHw2MjM3NDc2ZDBmNGI5MjAwNjkyNDFlYzYiLCJhdWQiOiJnQWtEbjlUSmxFbURxc2M2Mk1ZZENpTmMydFZQMHFMcCIsImlhdCI6MTY0ODcyOTg2MSwiZXhwIjoxNjQ4NzY1ODYxLCJub25jZSI6Ik1sYzFPWFZIVGxGVloxRXhRak54U1d4MlVtWnlTVWg2TVZKMGJXOXNXbUZZTWtsRGVXUmlSMjkzVFE9PSJ9.FfHijwgVuKXonQRqw_X91w_-eygKHTNQlBmv5bWaI8fy2RIwQTMQUnmhq5qaCOAtNt7keqs76xbkoDuhCGlHVnTAFMVfnQLPjG7-gC8jM1sr_zfHDgKjS4bDLGsgsriZkhBuRg9IpTlAbuk0ZXPR4QqBOeRJuSXl3wHSovoM0R8gS2cXZbo7y2AYfmkWPwWb8qkux7RnmZkAXxoygViS3ED52iv_5h_yyLIRcPyGDNeZTppouINIqlaI5yQM-LLJVX1E1w4dP9NfOaVNz8sNlILnUILbAgahZj52av5I1QsY7HkqpcF3PeV2veKV8DV2CUNNAAsMp5aaec34fQ-MyA"

```

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [March 31, 2022, 4:39pm UTC](https://community.auth0.com/t/need-help-on-getting-idtoken-user-metadata-with-react-auth0-sdk/80740/5 "2022-03-31T16:39:12Z")

</div>

Hi @dudumonteiro,

Thank you for your response.

The issue involves using one of the reserved namespaces. As described in our [Create Custom Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-namespaced-custom-claims) documentation, namespace identifiers must use any non-Auth0 HTTP or HTTPS URL as a namespace identifier. Auth0 domains cannot be used as namespace identifiers, and include:

- [auth0.com](http://auth0.com)
- [webtask.io](http://webtask.io)
- webtask.run

Once the namespace has been fixed, you will be able to decode the custom claims correctly.

Hoped this helps!

Please let me know if you have additional questions.

Thank you.

---

<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:** [December 22, 2022, 10:48am UTC](https://community.auth0.com/t/need-help-on-getting-idtoken-user-metadata-with-react-auth0-sdk/80740/6 "2022-12-22T10:48:20Z")

</div>


