# Require MFA once per session rule only for enrolled users

**URL:** <https://community.auth0.com/t/require-mfa-once-per-session-rule-only-for-enrolled-users/93525>\
**Category:** Get Help\
**Tags:** rules, mfa, login, auth0\
**Created:** [November 1, 2022, 6:50pm UTC](https://community.auth0.com/t/require-mfa-once-per-session-rule-only-for-enrolled-users/93525 "2022-11-01T18:50:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yana.bobrysheva](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yana.bobrysheva/32/40972_2.png) [@yana.bobrysheva](https://community.auth0.com/u/yana.bobrysheva)\
**Post date:** [November 1, 2022, 6:50pm UTC](https://community.auth0.com/t/require-mfa-once-per-session-rule-only-for-enrolled-users/93525/1 "2022-11-01T18:50:54Z")

</div>

Is there a way to configure “Require MFA once per session” rule to be applicable only to the users who have enrolled in MFA instead of all users for whom MFA is enabled?

---

<div class="post-metadata">

**Author:** ![spoudel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/spoudel/32/51376_2.png) [@spoudel](https://community.auth0.com/u/spoudel)\
**Post date:** [November 2, 2022, 2:06pm UTC](https://community.auth0.com/t/require-mfa-once-per-session-rule-only-for-enrolled-users/93525/2 "2022-11-02T14:06:50Z")

</div>

You can add the following rule to accomplish it.

function requireMfaOncePerSession(user, context, callback) {  
let authMethods = ;  
if (context.authentication && Array.isArray(context.authentication.methods)) {  
authMethods = context.authentication.methods;  
}

const completedMfa = !!authMethods.find((method) =\> method.name === ‘mfa’);

if (completedMfa) {  
return callback(null, user, context);  
}

context.multifactor = {  
provider: ‘any’,  
allowRememberBrowser: false  
};

callback(null, user, context);  
}

---

<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:** [January 8, 2024, 8:54am UTC](https://community.auth0.com/t/require-mfa-once-per-session-rule-only-for-enrolled-users/93525/3 "2024-01-08T08:54:55Z")

</div>

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