Error fetching user metadata: TypeError: management.getUser is not a function

Hey @noahbelstad :wave:

Check out ManagementClient | auth0 on how to use the ManagementClient from the node client library.

In your case, it would look something like below:

const result = await management.users.get({ id: userId }); // Fetch result
const user = result.data || {}; // extract user from result

Note that the management calls you are making in other parts of your code for Client Grants, Updating users, etc will also need to be updated to prevent getting these errors.

Hope this helps!

2 Likes

That FetchError is occurring because the domain field is not set correctly when initializing the ManagementClient here:

// Initialize Auth0 Management Client
const management = new ManagementClient({
    domain: process.env.AUTH0_DOMAIN,
    clientId: process.env.AUTH0_CLIENT_ID,
    clientSecret: process.env.AUTH0_CLIENT_SECRET,
    scope: ‘read:users read:users_app_metadata update:users update:users_app_metadata read:client_grants create:client_grants update:client_grants delete:client_grants’
});

Based on the error you received, it suggests you are passing in https as the domain value

[cause]: Error: getaddrinfo ENOTFOUND https
        at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26) {
    errno: -3008,
    code: ‘ENOTFOUND’,
    syscall: ‘getaddrinfo’,
    hostname: ‘https’
}

Double check to make sure that process.env.AUTH0_DOMAIN is the actual Auth0 domain that includes the region + auth0.com address
(For example, just $AUTH0_TENANT.$REGION.auth0.com - do not include https:// )

2 Likes

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