Rule not used when creating a user via the Management API, is there an alternative approach?

Given our following rule:

function (user, context, callback) {
  var uuid = require("uuid");

  user.app_metadata = user.app_metadata || {};

  var promise = Promise.resolve(1);

  if (!user.app_metadata.uuid) {
    user.app_metadata.uuid = uuid();

    promise = auth0.users.updateAppMetadata(user.user_id, user.app_metadata);
  }

  promise.then(() => {
    if (context.idToken) {
      // Include the uuid in the issued ID token if applicable
      context.idToken["https://www.ourcompany.com/auth0-uuid"] = user.app_metadata.uuid;
    }

    if (context.accessToken) {
      // Include the uuid in the issued access token if applicable
      context.accessToken["https://www.ourcompany.com/uuid"] = user.app_metadata.uuid;
    }
    
    callback(null, user, context);
  }).catch(callback);
}

This rule is only executed when logging in via our Angular application. I like to be able to use this rule when I create a new user via the Management API. Now I understood from the documentation this is not possible because the rule is not called. I can confirm this because after having created some users, none of them have the required UUID.

The reason is I like to automatically create users for webload testing. Suppose I create 50 users, I need to manually log in every time to initialize the UUID in the claims. Of course this would be a 1 time operation, but I rather like to automate this.

Is there a solution to my problem? I read about converting rules to actions, but it is not clear if this is a solution.

Hey there @evert !

I believe creating a post registration Action mirroring the logic of the rule shared should do the trick. A post registration Action will be triggered regardless of if the user is created using the Auth0 Dashboard, Management API, or registering on the sign-up page.

Hope this helps!

1 Like

Thank you for replying to this issue!

I will try this.

No problem, happy to help!

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