# Adding User to Role in Actions does not work

**URL:** <https://community.auth0.com/t/adding-user-to-role-in-actions-does-not-work/199448>\
**Category:** Get Help\
**Tags:** management-api, roles\
**Created:** [April 29, 2026, 11:32am UTC](https://community.auth0.com/t/adding-user-to-role-in-actions-does-not-work/199448 "2026-04-29T11:32:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![armen.yeri](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/armen.yeri/32/79210_2.png) [@armen.yeri](https://community.auth0.com/u/armen.yeri)\
**Post date:** [April 29, 2026, 11:32am UTC](https://community.auth0.com/t/adding-user-to-role-in-actions-does-not-work/199448/1 "2026-04-29T11:32:01Z")

</div>

None of the functions on existing blog posts work:

TypeError: management.roles.assignUsers is not a function

TypeError: management.users.assignRoles is not a function

TypeError: management.users.assignRolesToUser is not a function

How can I get this to work?

this is my current action:

exports.onExecutePostLogin = async (event, api) =\> {

// only run on first login

if (event.stats.logins\_count !== 1) {

```
return;

```

}

const { ManagementClient } = require(“auth0”);

const management = new ManagementClient({

```
domain: event.secrets.AUTH0_DOMAIN,

clientId: event.secrets.M2M_CLIENT_ID,

clientSecret: event.secrets.M2M_CLIENT_SECRET,

```

});

try {

```
await management.roles.assignUsers(

  { id: event.secrets.USER_ROLE_ID },

  {

    users: \[event.user.user_id\],

  }

);

```

} catch (e) {

```
console.log("Error assigning role:", e);

```

}

};

---

<div class="post-metadata">

**Author:** ![gerald.czifra](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gerald.czifra/32/75301_2.png) [@gerald.czifra](https://community.auth0.com/u/gerald.czifra)\
**Post date:** [April 29, 2026, 6:22pm UTC](https://community.auth0.com/t/adding-user-to-role-in-actions-does-not-work/199448/3 "2026-04-29T18:22:41Z")

</div>

Hi @armen.yeri

Welcome to the Auth0 Community!

If my understanding of the Action code is correct, you are trying to add a role to users the first time they login. The root cause of the issue seems to be the method used, please try again with `management.assignRolestoUser(params, data)` and let us know if it works.

I highly recommend reading through our Support Article on how to [Add a Default Role to a New User on First Login](https://support.auth0.com/center/s/article/How-do-I-add-a-default-role-to-a-new-user-on-first-login) which details all information on how to set it up, including a code snipper for the **Post Login** trigger to serve as a template.

Looking forward to your input!

Best regards,  
Gerald

---

<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:** [May 13, 2026, 6:23pm UTC](https://community.auth0.com/t/adding-user-to-role-in-actions-does-not-work/199448/4 "2026-05-13T18:23:03Z")

</div>

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