We setup a login flow rule to automatically assign a role to a user that has client_name = DeveloperPortal in the user metadata but are getting the following error when we run a test call.
SanitizedError [APIError]: getaddrinfo ENOTFOUND null
at /data/_verquire/_node16/@auth0/rule-utilities/0.2.0/node_modules/rest-facade/src/Client.js:402:25
at Request.callback (/data/_verquire/_node16/@auth0/rule-utilities/0.2.0/node_modules/superagent/lib/node/index.js:905:3)
at ClientRequest.<anonymous> (/data/_verquire/_node16/@auth0/rule-utilities/0.2.0/node_modules/superagent/lib/node/index.js:822:12)
at ClientRequest.emit (node:events:527:28)
at ClientRequest.emit (node:domain:475:12)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527:28)
at TLSSocket.emit (node:domain:475:12)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3) {
statusCode: 'ENOTFOUND',
requestInfo: { method: 'post', url: 'https://null' },
originalError: Error: getaddrinfo ENOTFOUND null
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'null',
response: undefined
}
}
here is the rule we created.
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
const namespace = "https://xxxxx.com";
const ManagementClient = require("auth0").ManagementClient;
const management = new ManagementClient({
domain: event.secrets.domain,
clientId: event.secrets.clientId,
clientSecret: event.secrets.clientSecret,
scope: "read:roles create:roles update:roles",
});
const devportalRole = { id :'xxxx'}; // This id must be a variable!!
var data = { "users" : [ event.user.user_id]};
try {
// if (event.authorization) {
if (!event.user.email_verified) {
return;
} else if (event.user.user_metadata.client_name === "DeveloperPortal") {
api.idToken.setCustomClaim(`${namespace}/roles`, ['DeveloperPortal - User']);
api.accessToken.setCustomClaim(`${namespace}/roles`, ['DeveloperPortal - User']);
await management.roles.assignUsers(devportalRole, data);
}
// }
} catch (e) {
console.log(e);
}
};
/**
* Handler that will be invoked when this action is resuming after an external redirect. If your
* onExecutePostLogin function does not perform a redirect, this function can be safely ignored.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
// exports.onContinuePostLogin = async (event, api) => {
// };
Not sure where my issue is, could use some help with the script…