# Actions not setting claims/roles in JWT

**URL:** <https://community.auth0.com/t/actions-not-setting-claims-roles-in-jwt/98892>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [January 25, 2023, 6:45am UTC](https://community.auth0.com/t/actions-not-setting-claims-roles-in-jwt/98892 "2023-01-25T06:45:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jarl-plateo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jarl-plateo/32/43207_2.png) [@jarl-plateo](https://community.auth0.com/u/jarl-plateo)\
**Post date:** [January 25, 2023, 6:45am UTC](https://community.auth0.com/t/actions-not-setting-claims-roles-in-jwt/98892/1 "2023-01-25T06:45:59Z")

</div>

Hello,

I have been trying for the past few days to get roles into the access token. To be fair, I am about to give up and move to a different provider because it seems to be so difficult, for such a simple thing.

I have tried every rule and action I have come across. I am using Authorization Core instead of the extension.

I have even tried to copy paste this action:

> **[Login Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow#add-user-roles-to-id-and-access-tokens)**
>
> Learn about the Actions Login Flow and the post-login Action trigger, which is executed after a user logs in and when a Refresh Token is requested.

And it still doesn’t work.

I have tried setting dummy claims like this:

```auto
api.idToken.setCustomClaim('myClaim', 'this is a private, non namespaced claim');
api.accessToken.setCustomClaim('myClaim', 'this is a private, non namespaced claim');

```

And still no luck.

This is my current action:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://example.com';

  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
  }
};

```

I have also tried to follow this one:

> **[Sample Use Cases: Scopes and Claims](https://auth0.com/docs/get-started/apis/scopes/sample-use-cases-scopes-and-claims#add-custom-claims-to-a-token)**
>
> Learn how to use scopes and claims with applications and APIs.

I have also created an API and use that identity as `audience` during authorization but still no luck.

Best regards  
Jarl

---

<div class="post-metadata">

**Author:** ![jarl-plateo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jarl-plateo/32/43207_2.png) [@jarl-plateo](https://community.auth0.com/u/jarl-plateo)\
**Post date:** [January 26, 2023, 7:09pm UTC](https://community.auth0.com/t/actions-not-setting-claims-roles-in-jwt/98892/2 "2023-01-26T19:09:28Z")

</div>

In case someone else stumbles upon this and are using `nextauth` along with the Auth0 provider.  
You need to use the `account.access_token` property inside the `jwt` callback, to get the correct token instead of the `id_token`.

---

<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:** [January 26, 2023, 10:52pm UTC](https://community.auth0.com/t/actions-not-setting-claims-roles-in-jwt/98892/3 "2023-01-26T22:52:11Z")

</div>

Hi there @jarl-plateo welcome to the community!

Good to know you were able to resolve the issue and thanks a bunch for following up with your solution on this one - I’m sure it’ll be useful to someone moving forward 💪

---

<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:** [February 9, 2023, 10:52pm UTC](https://community.auth0.com/t/actions-not-setting-claims-roles-in-jwt/98892/4 "2023-02-09T22:52:26Z")

</div>

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