# Cannot bypass mfa in actions

**URL:** <https://community.auth0.com/t/cannot-bypass-mfa-in-actions/140490>\
**Category:** Get Help\
**Tags:** one-time-password-otp-factor, mfa\
**Created:** [August 6, 2024, 7:47am UTC](https://community.auth0.com/t/cannot-bypass-mfa-in-actions/140490 "2024-08-06T07:47:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrdevmar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chrdevmar/32/52173_2.png) [@chrdevmar](https://community.auth0.com/u/chrdevmar)\
**Post date:** [August 6, 2024, 7:47am UTC](https://community.auth0.com/t/cannot-bypass-mfa-in-actions/140490/1 "2024-08-06T07:47:43Z")

</div>

Hello all, I am implementing optional 2fa into a react web app and encountering an issue where `getAccessTokenSilently` always fails with a `Multifactor authentication required` error.

My approach is to check if the user has already passed mfa at least once in their session inside of the `onExecutePostLogin` action, and bypass mfa is that the base, my code looks like so:

```auto
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)
  }
};

```

When watching the logs in real time as I refresh the page (which results in a call to `getAccessTokenSilently`), I can see the action logging as I expect. It still always fails though.

The only other thing I can think of is that my audience that I am using for `loginWithRedirect` and `getAccessTokenSilently` is `https://{myDomain}/mfa/` and I am requesting scopes to be able to list/add authenticators. Is there another hidden layer of logic outside of my control that is always enforcing mfa based on the audience and scopes I am requesting?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 6, 2024, 10:31pm UTC](https://community.auth0.com/t/cannot-bypass-mfa-in-actions/140490/3 "2024-08-06T22:31:28Z")

</div>

Hey there @chrdevmar welcome to the community!

> [@chrdevmar](#):
>
> Is there another hidden layer of logic outside of my control that is always enforcing mfa based on the audience and scopes I am requesting?

This is exactly what looks to be happening, see the warning ⚠ [here](https://auth0.com/docs/secure/multi-factor-authentication/manage-mfa-auth0-apis/manage-authenticator-factors-mfa-api#universal-login).

 ![Screenshot 2024-08-06 at 4.31.06 PM](https://global.discourse-cdn.com/auth0/original/3X/3/6/368f083087950d4be9df5efae03d4c17e6490e7b.png)

---

<div class="post-metadata">

**Author:** ![chrdevmar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chrdevmar/32/52173_2.png) [@chrdevmar](https://community.auth0.com/u/chrdevmar)\
**Post date:** [August 6, 2024, 11:17pm UTC](https://community.auth0.com/t/cannot-bypass-mfa-in-actions/140490/4 "2024-08-06T23:17:26Z")

</div>

Ok thanks for confirming that, in that case I guess I will need to build my UX flow such that they have to interactively log in (seperate to their regular login) to get an mfa token at the time they want to add mfa to their account.

In terms of being to determine if they already have mfa setup, I was listing authenticators with the mfa api but I definitely don’t want to redirect them to the login screen just for this. Can I instead do this in the post login action by checking enrolled factors and attaching metadata to the user?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 7, 2024, 9:30pm UTC](https://community.auth0.com/t/cannot-bypass-mfa-in-actions/140490/5 "2024-08-07T21:30:37Z")

</div>

No problem, happy to help!

> [@chrdevmar](#):
>
> Can I instead do this in the post login action by checking enrolled factors and attaching metadata to the user?

Yes, assuming a non-MFA API audience you should just be able to check for enrolled factors - `event.user.multifactor` will provide an array of enrolled factors.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [August 21, 2024, 9:31pm UTC](https://community.auth0.com/t/cannot-bypass-mfa-in-actions/140490/6 "2024-08-21T21:31:00Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
