# Post User Registration Action - Module Not Found

**URL:** <https://community.auth0.com/t/post-user-registration-action-module-not-found/111312>\
**Category:** Get Help\
**Tags:** management-api, roles\
**Created:** [July 14, 2023, 8:16pm UTC](https://community.auth0.com/t/post-user-registration-action-module-not-found/111312 "2023-07-14T20:16:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shester](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shester/32/47464_2.png) [@shester](https://community.auth0.com/u/shester)\
**Post date:** [July 14, 2023, 8:16pm UTC](https://community.auth0.com/t/post-user-registration-action-module-not-found/111312/1 "2023-07-14T20:16:06Z")

</div>

I am attempting to add a default role in an action:

```auto
exports.onExecutePostUserRegistration = async (event, api) => {
    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};
    var data = { "roles" : ['rol_7OQ4PJQWyE0R0eQC']};

  management.assignRolestoUser(params, data, function (err) {
    if (err) {
      console.log(err)
    }
    else {
      console.log(`role ${data} successfully assigned to ${event.user.email}`)
    }
  });
};

```

However, this doesn’t seem to be working. I’ve checked the following:

1. The custom action is added in the Post User Registration flow between Start and Complete
2. The role ID is correct
3. I’ve attempted to check the logs under Monitoring → Logs (couldn’t find anything)
4. Run “test” on my action

When I run “test”, i get the following test results:

```auto
Test Results
Error:

{
  "code": "MODULE_NOT_FOUND",
  "message": "Cannot find module 'auth0'\nRequire stack:\n- /data/io/node18-actions/c1595553-1962-4752-8327-f211bf654dcc/webtask.js",
  "name": "Error",
  "stack": "Error: Cannot find module 'auth0'\nRequire stack:\n- /data/io/node18-actions/c1595553-1962-4752-8327-f211bf654dcc/webtask.js\n at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)\n at WebtaskModule._resolveFilename (/data/sandbox/lib/module.js:117:17)\n at WebtaskModule.require (/data/sandbox/lib/module.js:196:37)\n at require (/data/sandbox/lib/module.js:237:17)\n at exports.onExecutePostUserRegistration (/data/io/node18-actions/c1595553-1962-4752-8327-f211bf654dcc/webtask.js:9:30)\n at /data/io/f41345ae72392489c66a6a20d70b9659ecd408a1.js:5:890\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
}

Stats:

{
  "total_request_duration_ms": 265,
  "total_runtime_execution_duration_ms": 261,
  "runtime_processing_duration_ms": 5,
  "action_duration_ms": 188,
  "runtime_external_call_duration_ms": 68,
  "boot_duration_ms": 73,
  "network_duration_ms": 5
}

```

I thought Node v18 was the issue so I created the same action using Node v16. When I test, I have no issues. However, it still does not add the role to the user.

I do not want to add RBAC, but I tried turning that on with permissions as well. Still no luck.

I am attempting to manage roles-only in Auth0 and add to a Hasura claim. My post login action to add the claims is working, but it’s of no use without this default role setup.

Note: I also tried setting my Extensibility to Node 18 and it made no difference. I also thought that maybe the fact that I kept adding and deleting the same user was causing the issue since the history persisted across deletions so maybe the post registration action doesn’t fire in that case? I tried creating other users to test this theory and it still didn’t work.

Please help. Thanks.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [July 15, 2023, 4:17am UTC](https://community.auth0.com/t/post-user-registration-action-module-not-found/111312/3 "2023-07-15T04:17:49Z")

</div>

Hi @shester,

Thanks for reaching out to the Auth0 Community!

The “Module Not Found” error happens when a module used in your Action script has not been added as a dependency. This error is now thrown when using Node 18 in Actions.

In this case, you will need to specify the `auth0` module as a dependency in the Action script’s **Dependencies** section. See below:

![image](https://global.discourse-cdn.com/auth0/original/3X/b/8/b85b34e9497ce2eee593c7a3f6c66e8a712ee9ba.png)

If you require additional modules, please check out our [Can I require? - Search which node modules you can use in webtask.io](https://auth0-extensions.github.io/canirequire/#auth0).

Next, when looking at your code snippet I don’t see anything that stands out to be an issue with the script not adding the role. It might be helpful to follow the guide provided in our [How can I use the Management API in Actions?](https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947) FAQ to see if you can get it working that way.

Please let me know how this goes for you.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![shester](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shester/32/47464_2.png) [@shester](https://community.auth0.com/u/shester)\
**Post date:** [July 15, 2023, 1:17pm UTC](https://community.auth0.com/t/post-user-registration-action-module-not-found/111312/4 "2023-07-15T13:17:51Z")

</div>

Thanks. I was able to solve my issue using the tutorial you provided: [How can I use the Management API in Actions?](https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947)

However, I want to point out that on step 2, it says “2. Authorize it to use the Management API with the required scopes:” and only shows the need for the `update:roles` permission. When providing this permission alone, it did not work:

```auto
{
  "action_name": "Assign Role On First Login",
  "response": {
    "logs": "Forbidden: Insufficient scope, expected any of: read:roles,update:users,create:role_members\n at /data/layers/layers-NCEn/NCEnN1oWAIpnwGrXpY_KwQ87kXoeGbwCOW9Qt4Ssh0M/node_modules/rest-facade/src/Client.js:402:25\n at Request.callback (/data/layers/laye",
    "stats": {
      "total_request_duration_ms": 1017,
      "total_runtime_execution_duration_ms": 1013,
      "runtime_processing_duration_ms": 5,
      "action_duration_ms": 1008,
      "boot_duration_ms": 5,
      "network_duration_ms": 4
    }
  },
  "started_at": "2023-07-15T13:11:04.503739087Z",
  "ended_at": "2023-07-15T13:11:05.521390576Z"
}

```

I also added the `read:roles` permission and it worked, though I assume adding any of the roles specified would do the trick `read:roles,update:users,create:role_members`

Just wanted to point this out. Maybe you could have someone update that blog post. Thanks.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [July 20, 2023, 4:22pm UTC](https://community.auth0.com/t/post-user-registration-action-module-not-found/111312/5 "2023-07-20T16:22:52Z")

</div>

Hi @shester,

Thanks for your reply and for providing us with feedback on the required scopes. I have just tested your observation and was successfully able to assign a user to a role with only the `update:roles` scope. However, when checking the Management API’s [Assign users to a role](https://auth0.com/docs/api/management/v2/roles/post-role-users#endpoint) endpoint, it expects `update:roles` and `create:role_members` as the required scopes. I will look further into this and see what needs to be updated. Thanks for bringing this to our attention.

Please let us know if you have additional questions.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [August 3, 2023, 4:40pm UTC](https://community.auth0.com/t/post-user-registration-action-module-not-found/111312/7 "2023-08-03T16:40:23Z")

</div>

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