# Writing an Action to combine User Roles and Member Roles

**URL:** <https://community.auth0.com/t/writing-an-action-to-combine-user-roles-and-member-roles/181587>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [February 6, 2025, 2:38pm UTC](https://community.auth0.com/t/writing-an-action-to-combine-user-roles-and-member-roles/181587 "2025-02-06T14:38:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan74](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jonathan74/32/59823_2.png) [@jonathan74](https://community.auth0.com/u/jonathan74)\
**Post date:** [February 6, 2025, 2:38pm UTC](https://community.auth0.com/t/writing-an-action-to-combine-user-roles-and-member-roles/181587/1 "2025-02-06T14:38:07Z")

</div>

Ready to post? 🔍 First, try searching for your answer.  
I’m trying to create a post login action to combine user roles (assigned in Console / Users) with member roles (Console / Organizations / Members / Roles) to provide my backend with a consistent set of roles. I don’t want to be sensitive to how the roles were assigned, just to understand that the role was assigned. However my code below still doesn’t seem to receive the user roles. Any suggestions?

```auto
exports.onExecutePostLogin = async (event, api) => {
    const namespace = "com.mydomain.";

    const orgRoles = (event.authorization && event.authorization.roles) ? event.authorization.roles : [];
    const userRoles = (event.user && event.user.roles) ? event.user.roles : [];

    const roles = Array.from(new Set([...orgRoles, ...userRoles]));

    if (roles.length > 0) {
        api.accessToken.setCustomClaim(namespace + "roles", roles);
    }

};

```

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [February 24, 2025, 1:39am UTC](https://community.auth0.com/t/writing-an-action-to-combine-user-roles-and-member-roles/181587/3 "2025-02-24T01:39:31Z")

</div>

Hi @jonathan74

Welcome to the Auth0 Community!

Thank you for posting your question. We have an excellent knowledge solution that covers the topic of assigning the roles and permission to the access token → [How to Add Roles and Permissions to the ID Token Using Actions](https://community.auth0.com/t/how-to-add-roles-and-permissions-to-the-id-token-using-actions/84506)

Regarding your code, the event.user.roles is populated if you are using the Authorization Extension; if not, all user roles will be set at the event.authentication.roles level.

Thanks  
Dawid

---

<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 10, 2025, 1:40am UTC](https://community.auth0.com/t/writing-an-action-to-combine-user-roles-and-member-roles/181587/5 "2025-03-10T01:40:31Z")

</div>

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