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.