# Add default Role via Rule after sign up New User does not add this role to the user in the Management Portal

**URL:** <https://community.auth0.com/t/add-default-role-via-rule-after-sign-up-new-user-does-not-add-this-role-to-the-user-in-the-management-portal/75387>\
**Category:** Get Help\
**Tags:** sdk, rule, auth0\
**Created:** [December 23, 2021, 11:06am UTC](https://community.auth0.com/t/add-default-role-via-rule-after-sign-up-new-user-does-not-add-this-role-to-the-user-in-the-management-portal/75387 "2021-12-23T11:06:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evert](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/evert/32/30553_2.png) [@evert](https://community.auth0.com/u/evert)\
**Post date:** [December 23, 2021, 11:06am UTC](https://community.auth0.com/t/add-default-role-via-rule-after-sign-up-new-user-does-not-add-this-role-to-the-user-in-the-management-portal/75387/1 "2021-12-23T11:06:49Z")

</div>

I have created the following rule:

```auto
function (user, context, callback) {
  	const ManagementClient = require('auth0@2.35.0').ManagementClient;

    const management = new ManagementClient({
      token: auth0.accessToken,
      domain: auth0.domain
    });
  
  	console.log(auth0.accessToken);
    const count = context.stats && context.stats.loginsCount ? context.stats.loginsCount : 0;
    if (count > 1) {
        return callback(null, user, context);
    }

    const params = { id : user.user_id};
    const data = { "roles" : ["Trial"]};

    management.users.assignRoles(params, data, function (err, user) {
      if (err) {
        // Handle error.
        console.log(err);
      }
		console.log("success");
    callback(null, user, context);
    });
}

```

I enabled RBAC and if I sign up a new user with name and password I do not see the role ‘Trial’ being added to the ‘Roles’ section in the Auth0 user management portal.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 23, 2021, 7:08pm UTC](https://community.auth0.com/t/add-default-role-via-rule-after-sign-up-new-user-does-not-add-this-role-to-the-user-in-the-management-portal/75387/3 "2021-12-23T19:08:52Z")

</div>

Hi @evert,

Can you try adding the specific role ID to the rule (not the role name). You can find it on the role setting page in the dashboard.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/1/2/1257c3ed0827c2d2e50dce02f7f4c6f2b40937a2.png)

---

<div class="post-metadata">

**Author:** ![evert](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/evert/32/30553_2.png) [@evert](https://community.auth0.com/u/evert)\
**Post date:** [December 27, 2021, 12:57pm UTC](https://community.auth0.com/t/add-default-role-via-rule-after-sign-up-new-user-does-not-add-this-role-to-the-user-in-the-management-portal/75387/4 "2021-12-27T12:57:43Z")

</div>

Dear Dan,

Great help (again)! Supplying the role ID works!

Maybe Auth0 could create a default rule for this requirement because I can imagine there is definitely a need for this.

Best regards,

Ever

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 4, 2022, 8:02pm UTC](https://community.auth0.com/t/add-default-role-via-rule-after-sign-up-new-user-does-not-add-this-role-to-the-user-in-the-management-portal/75387/5 "2022-01-04T20:02:18Z")

</div>

Glad that worked! Thanks for the feedback as well!

---

<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:** [January 19, 2022, 8:03pm UTC](https://community.auth0.com/t/add-default-role-via-rule-after-sign-up-new-user-does-not-add-this-role-to-the-user-in-the-management-portal/75387/6 "2022-01-19T20:03:01Z")

</div>

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