How to use Auth0 management API to retrieve user metadata

Hi,

I need to retrieve user metadata on “Post Change Password” action. Docs says user_metadata can not be retrieved using event.user.user_metadata. So i am planning to use mgmt API and pass user_id to getUser API. With the response from getUser i am planning to retrieve user_metadata attribute. I have the following code which is not working.

const { ManagementClient } = require('auth0');

exports.onExecutePostChangePassword = async (event) => {
try {
const auth0 = new ManagementClient({
    domain: event.secrets.domain,
    clientId: event.secrets.clientID,
    clientSecret: event.secrets.clientSecret,
  });
const user_id = event.user.user_id
  const user = await auth0.getUser({ id: user_id });

  console.log('User Details:', user);
} catch (err) {
    console.log(`Error sending email to ${event.user.email}:`, err.message)
  }
};

But when testing in actions page, i get this error

auth0.getUser is not a function

Any suggestions?

i figured this out.

await management.users.get({ id: USER_ID }, function (err, user) {
console.log(user);
});

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