Hello,
We are using the following action to capture and save the user’s phone number in the user׳s app_metadata.
(we have SMS MFA always on):
exports.onExecutePostLogin = async (event, api) => {
if (event.user.app_metadata.phoneNumber) return
const ManagementClient = require('auth0').ManagementClient;
const management = new ManagementClient({
domain: event.secrets.domain,
clientId: event.secrets.clientId,
clientSecret: event.secrets.clientSecret,
});
console.log('created Auth0 Client')
const guardianEnrollments = await management.getGuardianEnrollments({ id: event.user.user_id }) || []
console.log('guardianEnrollments: ' + JSON.stringify(guardianEnrollments))
const smsEnrollment = guardianEnrollments.find(e => e.type === 'sms')
if (!smsEnrollment) return
const {phone_number} = smsEnrollment
api.user.setAppMetadata('phoneNumber',phone_number)
return
};
The problem is that on the first login - the one that prompts the user to insert his phone number and enroll in the MFA, we get “[ ]” as the “guardianEnrollments”.
*we got this “[ ]” value immediately after the user enter his credentials and before he is prompted to insert his number…
**on the following logins, the action is working fine, and we get the correct “guardianEnrollments”