I am attempting to add a default role in an action:
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:
- The custom action is added in the Post User Registration flow between Start and Complete
- The role ID is correct
- I’ve attempted to check the logs under Monitoring → Logs (couldn’t find anything)
- Run “test” on my action
When I run “test”, i get the following test results:
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.