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) => {
// };