I have implemented MFA with email challenge in post action login. When user refresh the browser, React auth0 component method getTokenSilently() throws exception that ‘Error fetching access token: Fm: Multifactor authentication required’.
Implemented the solution from Auth0 documentation and Auth0 community topic suggestions. The solution not works for us.
Auth0 documentation:
exports.onExecutePostLogin = async (event, api) => {
const authMethods = event.authentication?.methods ||
const completedMfa = !!authMethods.find((method) => method.name === ‘mfa’)
if (!completedMfa) {
api.multifactor.enable(‘any’, { allowRememberBrowser: true })
}
};
Solution from exsiting topic in Auth0 community:
exports.onExecutePostLogin = async (event, api) => {
if(event.authentication) {
console.log(event.authentication)
if (event.authentication.methods.find(({ name }) => name === ‘mfa’) ) {
console.log(‘mfa already passed, disabling for this login attempt’)
api.multifactor.enable(“none”);
}
} else {
console.log(‘no authentication methods recorded’, event)
}
};
We tried above solution in trigger order prior as well as next to Post login action of MFA challenge. The solution not working.