# MFA for login only

**URL:** <https://community.auth0.com/t/mfa-for-login-only/126531>\
**Category:** Get Help\
**Tags:** phone-factor, mfa\
**Created:** [February 5, 2024, 4:14pm UTC](https://community.auth0.com/t/mfa-for-login-only/126531 "2024-02-05T16:14:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![charles.nguyen-viet](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@charles.nguyen-viet](https://community.auth0.com/u/charles.nguyen-viet)\
**Post date:** [February 5, 2024, 4:14pm UTC](https://community.auth0.com/t/mfa-for-login-only/126531/1 "2024-02-05T16:14:42Z")

</div>

Hi,

Is it possible to turn on MFA only on the login but not on the create new user?

Regards,

---

<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:** [February 6, 2024, 11:15pm UTC](https://community.auth0.com/t/mfa-for-login-only/126531/3 "2024-02-06T23:15:35Z")

</div>

Hey there @charles.nguyen-viet !

I just want to clarify the expected behavior here - When a user goes to sign up for your application (and subsequently log in) you’d like to forego MFA. However, on all subsequent logins you wish for MFA to be in place?

If this is the case, you should be able to achieve this by working within a [Post Login Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/event-object) - The following action is a simple example of only challenging a user for MFA after their initial login:

```auto
exports.onExecutePostLogin = async (event, api) => {
  // Check if it's not the user's first login
  if (event.stats && event.stats.logins_count > 1) {
    // Trigger MFA challenge
    api.multifactor.enable('any');
  }
};

```

---

<div class="post-metadata">

**Author:** ![charles.nguyen-viet](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@charles.nguyen-viet](https://community.auth0.com/u/charles.nguyen-viet)\
**Post date:** [February 7, 2024, 2:27pm UTC](https://community.auth0.com/t/mfa-for-login-only/126531/4 "2024-02-07T14:27:28Z")

</div>

Hi @ty.frith ,

Thank you for your reply.  
Yes that’s the idea.

When I added the script in the Post Login Action, the application is still asking to scan the QR code  
(Google authenticator) after sign up.

Regards,

---

<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:** [February 8, 2024, 1:06am UTC](https://community.auth0.com/t/mfa-for-login-only/126531/5 "2024-02-08T01:06:34Z")

</div>

Thanks for confirming!

> [@charles.nguyen-viet](#):
>
> When I added the script in the Post Login Action, the application is still asking to scan the QR code  
> (Google authenticator) after sign up.

I forgot to mention that you need to toggle MFA to _Never_ in the Security → Multi-Factor Auth settings in your dashboard. This should allow an initial login without enforcing MFA while requiring it for all subsequent logins.

This is a similar pattern to enabling MFA for a subset of users:

[https://community.auth0.com/t/how-to-enable-mfa-for-a-subset-of-users/87505](https://community.auth0.com/t/how-to-enable-mfa-for-a-subset-of-users/87505)

---

<div class="post-metadata">

**Author:** ![charles.nguyen-viet](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@charles.nguyen-viet](https://community.auth0.com/u/charles.nguyen-viet)\
**Post date:** [February 12, 2024, 2:33pm UTC](https://community.auth0.com/t/mfa-for-login-only/126531/6 "2024-02-12T14:33:50Z")

</div>

Thank you very much, it works!

---

<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:** [February 12, 2024, 11:11pm UTC](https://community.auth0.com/t/mfa-for-login-only/126531/7 "2024-02-12T23:11:48Z")

</div>

Awesome!! Thanks for confirming 🙂

---

<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:** [February 26, 2024, 11:12pm UTC](https://community.auth0.com/t/mfa-for-login-only/126531/8 "2024-02-26T23:12:08Z")

</div>

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