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

I have created the following rule:

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.

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.

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

1 Like

Glad that worked! Thanks for the feedback as well!

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