Assigning Users On Sign Up

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

// Check if the user has a role assigned

if (event.authorization && event.authorization.roles && event.authorization.roles.length === 0) {

const ManagementClient = require(“auth0”).ManagementClient;

const management = new ManagementClient({

domain: "CantShowDomain",

clientId: "NotingToSee",

clientSecret: "Something Super Secret 007",

});

const params = { “id” : event.user.user_id };

const data = { “roles” : [“RoleId_here”] };

try {

console.log("Testing Flow")

console.log(params)

await management.users.assignRoles(params, data);

} catch (e) {

console.log(e);

}

}

};

in testing i replace the Identities , UserId with one in my application. and I get

TypeError: management.users.assignRoles is not a function
at exports.onExecutePostLogin (<action_code>:27:28)

Hi @tim.torpy

Welcome to the Auth0 Community!

Thank you for posting your question. Based on the code snippet that you provided, I think that the issue may be with how you assign the role to the user. Based on the Auth0 API documentation → node-auth0/reference.md at master · auth0/node-auth0 · GitHub

exports.onExecutePostLogin = async (event, api) => {
  // Check if the user has a role assigned
  if (event.authorization && event.authorization.roles && event.authorization.roles.length === 0) {
    const { ManagementClient } = require("auth0");

    const management = new ManagementClient({
      domain: "CantShowDomain",
      clientId: "NotingToSee",
      clientSecret: "Something Super Secret 007",
    });

    const roleId = "RoleId_here";
    const userId = event.user.user_id;

    try {
      console.log("Testing Flow");
      
      // Correct v5 syntax: assign(roleId, { users: [userIds] })
      await management.roles.users.assign(roleId, { 
        users: [userId] 
      });

    } catch (e) {
      console.log(e);
    }
  }
};

Thanks!
Dawid