Action is not adding role to user organization membership

Hello!

I have an Action to add a role to a user that is part of an organization, however when I check the member in the organization afterwards in the auth0 dashboard, they have no roles.

Eg after executing this post login action, I will still see no roles for the given user in the organization:

exports.onExecutePostLogin = async (event, api) => {
  const ManagementClient = require('auth0').ManagementClient;

  const management = new ManagementClient({
    domain: event.secrets.domain,
    clientId: event.secrets.clientId,
    clientSecret: event.secrets.clientSecret,
    scope: "update:roles update:users create:organization_member_roles",
  });

  const params = { id: event.organization?.id, user_id: event.user.user_id };
  const data = { roles: [event.secrets.someRoleId] }

  await management.organizations.addMemberRoles(params, data, function (err) {
    if (err) {
        console.log('err', err)
      }
    });
}

Any ideas what I could be missing? Thanks in advance!

Hi @steffanie,

After reviewing your code snippet, everything looks good.

Could you please let me know what kind of results you see when you run your Action script in the Action’s built-in debugger interface?

Thanks,
Rueben

Hi Rueben,

There are no errors when I run the Action with the test tool, but the response from addMemberRoles according to the docs is type undefined|Promise, if I console log the response it’s undefined.

1 Like

Silly me! I just checked the auth0 logs and saw that the client wasn’t granted the create:organization_member_roles scope, I just updated my app’s allowed scopes in the API dashboard and now it’s working :sweat_smile: Thank you!

1 Like

Hi @steffanie,

Ah yes! Good catch on the client not being granted the necessary scopes!

I’m glad that everything is working now!

Please reach out if there’s anything else we can do to help.

Thanks,
Rueben

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