Assign user role in login flow

hi everyone,
i have a auth0 automation to add a role to a user to the first login. with the new updates the row

      await management.assignRolestoUser(params, data);

no logner works, i cannot find any info with my search in the docs can anyone tell me how to do it now the code some month ago was working
the error is

TypeError: management.assignRolestoUser is not a function

here is the complete action

exports.onExecutePostLogin = async (event, api) => {
const result = event.transaction.redirect_uri === "site link";
console.log(result + " result of redirect uri " + event.transaction.redirect_uri);

  if (event.stats.logins_count > 1) {
    return;
  }
  
  if (event.transaction.redirect_uri === "site link") {
    const ManagementClient = require('auth0').ManagementClient;

    const management = new ManagementClient({
      domain: event.secrets.domain,
      clientId: event.secrets.clientId,
      clientSecret: event.secrets.clientSecret,
    });

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

    try {
      await management.assignRolestoUser(params, data);
      console.log(`Role ${data.roles} successfully assigned to ${event.user.email}`);
      api.idToken.setCustomClaim(`rules`, "rangerGestUser");
      api.accessToken.setCustomClaim(`rules`, "rangerGestUser");
    } catch (err) {
      console.log(err);
      // Handle error.
    }
  }
};

Hi @dpatrone1

Welcome back to the Auth0 Community!

I tested the action code on my end and I was able to reproduce the error that you are receiving.

As far as I have checked in regards to the NodeJS Management Client documentation, assignRolestoUser is not a valid function within the available list.

You can try following the steps provided in this blog post and use management.users.assignRoles(param, data) instead.

As an alternative, I would recommend to use the Management API or to use the updateUser function available within the Management Client.

If you have any other questions, let me know!

Kind Regards,
Nik