# Not getting roles

**URL:** <https://community.auth0.com/t/not-getting-roles/127184>\
**Category:** Get Help\
**Tags:** management-api, roles\
**Created:** [February 13, 2024, 6:09am UTC](https://community.auth0.com/t/not-getting-roles/127184 "2024-02-13T06:09:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pankaj.y](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pankaj.y/32/50388_2.png) [@pankaj.y](https://community.auth0.com/u/pankaj.y)\
**Post date:** [February 13, 2024, 6:09am UTC](https://community.auth0.com/t/not-getting-roles/127184/1 "2024-02-13T06:09:43Z")

</div>

When i’m trying to get user roles in access token it does not work for me  
what i’m doing wrong can anyone help me to figure out1  
This is my action code

```auto
exports.onExecutePostLogin = async (event, api) => {
    const ManagementClient = require("auth0").ManagementClient;
     const management = new ManagementClient({
        domain: event.secrets.domain,
        clientId: event.secrets.clientId,
        clientSecret: event.secrets.clientSecret,
    });
    const userRoles = await management.users.roles(event.user.user_id);

    api.accessToken.setCustomClaim("roles", userRoles);
};

```

error i’m getting  
management.users.roles is not a function

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [February 13, 2024, 1:36pm UTC](https://community.auth0.com/t/not-getting-roles/127184/3 "2024-02-13T13:36:06Z")

</div>

Hi @pankaj.y ,

Thanks for sharing!

You’re missing [namespace identifier in your custom claim](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims) + you do not need to use the ManagementClient here to get user roles, will be good to use `event.authorization.roles`. [Actions Triggers: post-login - Event Object](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/event-object)

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

```

Please let us know if that works for you!

---

<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 27, 2024, 1:36pm UTC](https://community.auth0.com/t/not-getting-roles/127184/4 "2024-02-27T13:36:46Z")

</div>

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