# Can't find custom claims in idToken

**URL:** <https://community.auth0.com/t/cant-find-custom-claims-in-idtoken/183847>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [March 13, 2025, 3:56pm UTC](https://community.auth0.com/t/cant-find-custom-claims-in-idtoken/183847 "2025-03-13T15:56:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![melek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/melek/32/71597_2.png) [@melek](https://community.auth0.com/u/melek)\
**Post date:** [March 13, 2025, 3:56pm UTC](https://community.auth0.com/t/cant-find-custom-claims-in-idtoken/183847/1 "2025-03-13T15:56:39Z")

</div>

I’m trying to add roles as a custom claim in user’s idToken. I’m running the following post-login action.

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
  }
}

```

I’m checking for it like this on my dashboard component.

```auto
  const { user, isLoading, error} = useUser();
  if (user){
    console.log(user['https://my-app.example.com/roles'])
  }

```

It’s returning undefined.

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [March 13, 2025, 4:57pm UTC](https://community.auth0.com/t/cant-find-custom-claims-in-idtoken/183847/3 "2025-03-13T16:57:52Z")

</div>

Hi @melek

Welcome to the Auth0 Community!

I have attempted to reproduce the issue on my end however everything works as expected.  
This is the console log in my application:

![image](https://global.discourse-cdn.com/auth0/optimized/3X/b/b/bb4943ad0d7f32f5ee46bd048255188349c15850_2_690x40.png)

And this is the claim inside the token:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/2/5/25aa01a44c4af3daa96ff618259337aa47405402.png)

I would recommend you to review our documentation regarding [creating custom claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#namespaced-guidelines) and to check if you are respecting our namespace guidelines.

If you have any other questions, feel free to leave a reply!

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![melek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/melek/32/71597_2.png) [@melek](https://community.auth0.com/u/melek)\
**Post date:** [March 13, 2025, 5:16pm UTC](https://community.auth0.com/t/cant-find-custom-claims-in-idtoken/183847/4 "2025-03-13T17:16:31Z")

</div>

Hi @nik.baleca,

I don’t think the issue is with the namespace as I’m using the exact same namespace `https://my-app.example.com/`

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [March 13, 2025, 6:26pm UTC](https://community.auth0.com/t/cant-find-custom-claims-in-idtoken/183847/5 "2025-03-13T18:26:27Z")

</div>

I see

Could you let me know what SDK/Sample app are you using?

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![melek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/melek/32/71597_2.png) [@melek](https://community.auth0.com/u/melek)\
**Post date:** [March 13, 2025, 7:04pm UTC](https://community.auth0.com/t/cant-find-custom-claims-in-idtoken/183847/6 "2025-03-13T19:04:36Z")

</div>

I’m using version auth0 v4.1.0 with next js v15.2.1

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [March 14, 2025, 8:41pm UTC](https://community.auth0.com/t/cant-find-custom-claims-in-idtoken/183847/7 "2025-03-14T20:41:38Z")

</div>

Hi again.

By any chance, if you log the claim outside of the if statement, does it work?

Does your user have assigned roles to it inside the Auth0 Dashboard?

After some testing, I still could not reproduce the issue on my end.

I can recommend to log the user to see if the roles are being mapped to the custom claim, however, if you try the following:

```auto
    console.log(user["https://my-app.example.com/roles"])

```

or

```auto
const key = "https://my-app.example.com/roles"
console.log(user[key])

```

Both of these should return the same value of the custom claim that you have set inside the action.

If you have any other questions on the matter, let me know.

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 28, 2025, 8:42pm UTC](https://community.auth0.com/t/cant-find-custom-claims-in-idtoken/183847/8 "2025-03-28T20:42:14Z")

</div>

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