How to enroll MFA for user in actions during resetpassword?

I tried to create a action after Password Reset / Post Challenge, what I try to do is when user try to reset password, verify with MFA first, but if user is not registered in MFA, enroll user with it first then go to password change page. I got following error when checking the logs: api.authentication.enrollWith is not a function. By the way the challengeWith function are working fine.

/**
 * Handler that will be called during the execution of a Password Reset / Post Challenge Flow.
 *
 * @param {Event} event - Details about the post challenge request.
 * @param {PasswordResetPostChallengeAPI} api - Interface whose methods can be used to change the behavior of the post challenge flow.
 */
const axios = require("axios");
exports.onExecutePostChallenge = async (event, api) => {
  const domainName = event.secrets.AUTH0_DOMAIN;
  const clientId = event.secrets.CLIENT_ID;
  if (event.user.enrolledFactors.length > 1) {
    api.authentication.challengeWith({
      type: 'otp'
    }, {
      additionalFactors: [{
        type: 'recovery-code'
      }, {
        type: 'email'
      }]
    })

    var options = {
      method: 'GET',
      url: `https://${domainName}/v2/logout`,
      headers: { 'content-type': 'application/json' },
      data: {
        client_id: clientId, federated: true
      }
    };

    axios.request(options).then(function (response) {
      console.log(response.data);
    }).catch(function (error) {
      console.error(error);
    });
  }
  else{
    api.authentication.enrollWith([{
      type: 'otp'
    }])
  }
};


/**
 * Handler that will be invoked when this action is resuming after an external redirect. If your
 * onExecutePostChallenge function does not perform a redirect, this function can be safely ignored.
 *
 * @param {Event} event - Details about the user and the context in which they are logging in.
 * @param {PasswordResetPostChallengeAPI} api - Interface whose methods can be used to change the behavior of the post challenge flow.
 */
// exports.onContinuePostChallenge = async (event, api) => {
// };

As the error mentions, the post-challenge API object in Password Reset Flow does not have an “enroll with” function. Look into this documentation for all the available functions:

1 Like

so is it possible to enroll MFA if they are not in post-challenge? Or in my case, do you have any suggestion what I should do about it ? @spoudel

Have you tried running it without the enroll with function?

yes, and there are no enroll page at all during the whole reset password process.