# Question about custom action (from a newbie)

**URL:** <https://community.auth0.com/t/question-about-custom-action-from-a-newbie/110184>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [June 28, 2023, 5:01pm UTC](https://community.auth0.com/t/question-about-custom-action-from-a-newbie/110184 "2023-06-28T17:01:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![asmith2306](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/asmith2306/32/48402_2.png) [@asmith2306](https://community.auth0.com/u/asmith2306)\
**Post date:** [June 28, 2023, 5:01pm UTC](https://community.auth0.com/t/question-about-custom-action-from-a-newbie/110184/1 "2023-06-28T17:01:30Z")

</div>

Hi,

This is my first post here, so hello!

I wanted Roles populated in the JWT for my Application so I wrote a custom Action and used it in a Login Flow. It works fine. A question I have is about the Javascript. I used the code from [this example in the docs](https://auth0.com/docs/manage-users/access-control/sample-use-cases-actions-with-authorization#add-user-roles-to-tokens), however I want to exclude the namespace so the function will look like this:

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.authorization) {
    api.idToken.setCustomClaim('roles', event.authorization.roles);
    api.accessToken.setCustomClaim('roles', event.authorization.roles);
  }
}

```

For some reason this doesn’t work without the namespace being appended to roles (as in the docs example). These setters are setting values in a simple map (I assume) so why doesn’t my code without the namespace work?

Thanks

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 28, 2023, 5:04pm UTC](https://community.auth0.com/t/question-about-custom-action-from-a-newbie/110184/3 "2023-06-28T17:04:44Z")

</div>

Hi there @asmith2306 welcome to the community!

> [@asmith2306](#):
>
> For some reason this doesn’t work without the namespace being appended to roles (as in the docs example). These setters are setting values in a simple map (I assume) so why doesn’t my code without the namespace work?

This doesn’t work because `roles` is a [reserved claim](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#general-restrictions) - You’ll either need to use namespace (generally recommended) or a non-reserved string.

Cheers!

---

<div class="post-metadata">

**Author:** ![asmith2306](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/asmith2306/32/48402_2.png) [@asmith2306](https://community.auth0.com/u/asmith2306)\
**Post date:** [June 28, 2023, 5:54pm UTC](https://community.auth0.com/t/question-about-custom-action-from-a-newbie/110184/4 "2023-06-28T17:54:45Z")

</div>

Ok that makes sense. Another question to add is why roles is populated without the need for an Action/Flow in an API JWT, but not an Application JWT?

Thanks

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 28, 2023, 7:40pm UTC](https://community.auth0.com/t/question-about-custom-action-from-a-newbie/110184/5 "2023-06-28T19:40:37Z")

</div>

> [@asmith2306](#):
>
> Another question to add is why roles is populated without the need for an Action/Flow in an API JWT, but not an Application JWT?

I assume you are referring to access tokens vs. ID tokens - The roles are automatically included in an access token when utilizing RBAC as the access token is used in _authorization_ against an API whereas the ID token is used for _authentication_ purposes.

---

<div class="post-metadata">

**Author:** ![asmith2306](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/asmith2306/32/48402_2.png) [@asmith2306](https://community.auth0.com/u/asmith2306)\
**Post date:** [June 28, 2023, 8:06pm UTC](https://community.auth0.com/t/question-about-custom-action-from-a-newbie/110184/6 "2023-06-28T20:06:38Z")

</div>

Ok thanks. I’ll reading the docs, etc. Thanks for your time.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 28, 2023, 10:59pm UTC](https://community.auth0.com/t/question-about-custom-action-from-a-newbie/110184/7 "2023-06-28T22:59:58Z")

</div>

No problem, happy to help!

---

<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:** [July 12, 2023, 11:00pm UTC](https://community.auth0.com/t/question-about-custom-action-from-a-newbie/110184/8 "2023-07-12T23:00:01Z")

</div>

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