Angular management api best practices

Please fill out the following to the best of your ability. Doing so will help out the troubleshooting process

  • What are you trying to achieve? What is the use case or idea behind it?

I am trying to patch user metadata and wanted to make sure that we’re using the auth0.WebAuth and auth0.Management API’s properly (with auth0-js v9.3.3.).

Main Question
Should I be creating two different instances of auth0.WebAuth, one for the user and one for the management API? Or should I just be using one and passing the user’s access token to the auth0.Management?

Current Code

auth0 = new auth0.WebAuth({
clientID: AUTH_CONFIG.clientID,
domain: AUTH_CONFIG.domain,
responseType: 'token id_token',
audience: 'https://XXXX.auth0.com/api/v2/',
redirectUri: AUTH_CONFIG.callbackURL,
scope: 'openid profile update:current_user_metadata read:current_user',

});

public handleAuthentication() {
this.auth0.parseHash((err, authResult) => {
  if (err) {
    console.log(err);
  } else if (authResult && authResult.accessToken && authResult.idToken) {
    this._setSession(authResult);
    this.auth0_userMgmt = new auth0.Management({
      domain: 'XXXX.auth0.com',
      token: authResult.accessToken,
      scope: 'read:current_user update:current_user_metadata',
    });
    const { sub } = authResult.idTokenPayload;
    this.auth0_userMgmt.patchUserMetadata(sub, { foo: 'bar' }, (err, res) => {
      if (err) {
        console.log(err);
        return;
      }
      console.log('Updating Auth0 user_metadata.');
    });
    }
  }
  // navigate home to clear auth0 route params
  this.router.navigate(['/']);
});

}

Thank you.

Hey @christianarredondo,

As it has been more than a few months since this topic was opened and there has been no reply or further information provided from the community as to the existence of the issue we would like to check if you are still facing the described challenge?

We are more than happy to assist in any way! If the issue is still out there please let us know so we can create a new thread for better visibility, otherwise we’ll close this one in week’s time.

Thank you!

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