I have a flow that does the following
/**
* Handler that will be called during the execution of a PostChangePassword flow.
*
* @param {Event} event - Details about the user and the context in which the change password is happening.
*/
exports.onExecutePostChangePassword = async (event) => {
const { MGMT_DOMAIN, MGMT_ID, MGMT_SECRET } = event.secrets;
const ManagementClient = require('auth0').ManagementClient;
const management = new ManagementClient({
domain: MGMT_DOMAIN,
clientId: MGMT_ID,
clientSecret: MGMT_SECRET,
scope: 'read:users update:users',
});
try {
await management.updateUserMetadata({ id: event.user.user_id }, { is_password_initial: false });
} catch (error) {
console.error('An error occurred while updating user metadata:', error);
}
};
This code is setting is_password_initial
to false so that we know the user already set the password at least once. This value is used in our email template to chose what template to use (we wanted to use last_password_reset but it s not accessible in email template…)
Sadly, even tho the secret are set to our application, this is_password_initial is NEVER set to false, and remain to true all the time. It looks like I can’t authenticate bevause there is no client_credentials
grant type set, but since I use an SPA for application type, I can’t allow that option…
How am I supposed to update the user metadata on this post change password hook ?
What is wrong with my code ?