Adding User to Role in Actions does not work

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);

}

};

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 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