/*** Handler that will be called during the execution of a PostLogin flow.** @param {Event} event - Details about the user and the context in which they are logging in.* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.*/exports.onExecutePostLogin = async (event, api) => { if (event.authentication && event.authentication.riskAssessment && event.authentication.riskAssessment.assessments.NewDevice) { // Example condition: prompt MFA only based on the NewDevice // confidence level, this will prompt for MFA when a user is logging in // from an unknown device. let shouldPromptMfa; switch (event.authentication.riskAssessment.assessments.NewDevice.confidence) { case 'low': case 'medium': shouldPromptMfa = true; break; case 'high': shouldPromptMfa = false; break; case 'neutral': // When this assessor has no useful information about the confidence, // do not prompt MFA. shouldPromptMfa = false; break; } // It only makes sense to prompt for MFA when the user has at least one // enrolled MFA factor. const canPromptMfa = event.user.multifactor && event.user.multifactor.length > 0; if (shouldPromptMfa && canPromptMfa) { api.multifactor.enable('any', { allowRememberBrowser: true }); } }};
/*** Handler that will be called during the execution of a PostLogin flow.** @param {Event} event - Details about the user and the context in which they are logging in.* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.*/exports.onExecutePostLogin = async (event, api) => { if (!event.user.multifactor || event.user.multifactor.length == 0) { api.multifactor.enable('any', { allowRememberBrowser: true }); }};