Hi,
Got stuck here while migrating auth0 rule to action. Specifically with getting the users by email using the ManagementClient. Was expecting that this would work seamlessly as it did with Auth0 Rules.
const auth0 = require("auth0");
exports.onExecutePostLogin = async (event, api) => {
const ManagementClient = auth0.ManagementClient;
const management = new ManagementClient({
clientId: event.secrets.AUTH0_CLIENT_ID,
clientSecret: event.secrets.AUTH0_CLIENT_SECRET,
domain: event.secrets.DOMAIN
});
management.usersByEmail(event.user.email, function (err, users) {
cb(err, users);
});
};
With the code block above, I’m getting this error:
{
"message": "management.usersByEmail is not a function",
"name": "TypeError",
"stack": "TypeError: management.usersByEmail is not a function\n at auth0 (/data/io/node18-actions/f46fc91e-a5f3-4450-a202-542fd964e6c1/webtask.js:41:18)\n at /data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:3676:28\n at replenish (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:448:21)\n at /data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:453:13\n at eachOfLimit (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:479:36)\n at awaitable (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:212:32)\n at eachOfGeneric (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:514:16)\n at eachOf (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:628:16)\n at awaitable (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:212:32)\n at /data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:3675:9"
}
Just for verifying that I’m using the correct function name:
usersByEmail: UsersByEmailManager {
configuration: {
clientId: 'cf7EiMQP9nGVE3tvuXKjfIFFi33WoniO',
clientSecret: 'QVge4qMxzSISJASGYuUr9_bw5HCSaEBlvVinLVKBeJ3H-Vl_2PqFxJfcF9beClIV',
domain: 'bark-sandbox.us.auth0.com',
scope: 'read:users',
baseUrl: 'https://bark-sandbox.us.auth0.com/api/v2',
middleware: [Array],
parseError: [AsyncFunction: parseError]
},
fetchWithTimeout: [AsyncFunction (anonymous)],
fetch: [AsyncFunction (anonymous)],
middleware: [ [TokenProviderMiddleware], [TelemetryMiddleware] ],
fetchApi: [AsyncFunction: fetch],
parseError: [AsyncFunction: parseError],
timeoutDuration: 10000
}
What am I missing here?