Rule using node-auth0, AuthenticationClient is not a constructor


We are trying to create a rule to assign a default role to every new user. In order to assign this role we are using the node-auth0 library. Using the code from the node-auth0 documentation we are encountering errors:

ERROR: AuthenticationClient is not a constructor

Here is the complete code of our rule:

function (user, context, callback) {
  if (!context.authorization || context.authorization.roles.length === 0) {
    if ( && user.email_verified) {
      var AuthenticationClient = require('auth0').AuthenticationClient;
      var auth0 = new AuthenticationClient({
        domain: '{DOMAIN}',
        clientId: configuration.MGMT_API_ID,
        clientSecret: configuration.MGMT_API_SECRET
          audience: 'https://{DOMAIN}',
          scope: 'read:roles update:users'
        function(err, response) {
          if (err) {


          var ManagementClient = require('auth0').ManagementClient;
          var management = new ManagementClient({
            token: response.access_token,
            domain: '{DOMAIN}'

          var params =  { id: user.user_id };
          var data = { 'roles': [ '{ROLE_ID}' ] };

          management.assignRolestoUser(params, data, function (err) {
            if (err) {

          if (!context.authorization) {
            context.authorization = {};
            context.authorization.roles = [];

          callback(null, user, context);

I first tried using the ManagementClient instead of the AuthenticationClient but the same error is showing. Is there some special steps to do in order to be able to use the node-auth0 library in a rule?

Hi @paul.queruel,

Thanks for joining us in the Community.

Take a look at this FAQ:

Furthermore, check out this resource to see which modules are available in rules:

Please let me know if this works/doesn’t work for you.


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