ManagementClient is not a constructor

I am unable to use the auth0 Node.js client library from within Rules.

I get the following error:

 (node:6) UnhandledPromiseRejectionWarning: TypeError: ManagementClient is not a constructor

example code:

    global.getRoleIdsByName = global.getRolesByName || async function (role_names) {
        const ManagementClient = require('auth0').ManagementClient;
        const management = new ManagementClient({
            token: auth0.accessToken,
            domain: auth0.domain
        });
        let roles = await management.getRoles();
        return roles.filter(role => role_names.includes(role.name)).map(role => role.id);
    }

Note that this works just fine when executed from a local Node.js environment like my IDE.

I have seen this library being used (example) hence my confusion …

Regards,

Gerardo.

1 Like

for anyone else having struggled with this apparently adding the version fixed the problem:

const ManagementClient = require('auth0@2.23.0').ManagementClient;
6 Likes

Perfect! Glad to hear that and thanks for sharing it with the rest of community!

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