How to return callback data from managementAPI calls? Please help

When i have my auth0Manage object and make any sdk calls such as getUser, i am unable to return the data from the callback. The return value from calling “auth0Manage.getUser(authId, cb)” is a requestWrapper. I was hoping that i would be able to return my data from the callback and then in turn it is returned by the getUser call. Is it intended to be this way?

EXAMPLE:

var auth0Manage = new auth0.Management({
  domain: {YOUR_AUTH0_DOMAIN},
  token: authResult.idToken
});

const test = auth0Manage.getUser(AUTHID, (err, resp) => {
    return resp;
})
console.log(test);

This console.log prints out a requestWrapper instead of the data i need which is the resp object in the callback. Is there any way to get this information out or was this the intended flow for this?

Auth0.js v9
Calls made in react client

This is an asynchronous request, so Auth0.js will hand back the results to the callback function you provided. So you’ll need to handle the results within the function:

var auth0Manage = new auth0.Management({
  domain: {YOUR_AUTH0_DOMAIN},
  token: authResult.idToken
});

auth0Manage.getUser(AUTHID, (err, resp) => {
    if (err) {
      // be prepared for possible errors
      console.log(err);
    } else {
      // the resp object will have the user information
      console.log(resp);
    }
});

I guess i was having a frustrating day because this is a simple asynchronous js issue, not auth0 issue. I appreciate your time to respond, thank you Nicolas for clarifying.

1 Like

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