# Change MFA Factors during post-login trigger

**URL:** <https://community.auth0.com/t/change-mfa-factors-during-post-login-trigger/183660>\
**Category:** Get Help\
**Tags:** mfa-api, mfa\
**Created:** [March 10, 2025, 8:36pm UTC](https://community.auth0.com/t/change-mfa-factors-during-post-login-trigger/183660 "2025-03-10T20:36:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shawnyangkoho](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shawnyangkoho/32/73564_2.png) [@shawnyangkoho](https://community.auth0.com/u/shawnyangkoho)\
**Post date:** [March 10, 2025, 8:36pm UTC](https://community.auth0.com/t/change-mfa-factors-during-post-login-trigger/183660/1 "2025-03-10T20:36:45Z")

</div>

Hello, I am trying to implement this logic.  
During the post login trigger I want to do an actions like this:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const smsEnrolled = event.user.enrolledFactors?.some(({type}) => type === "phone");

  if (!smsEnrolled) {
    const ManagementClient = require('auth0').ManagementClient;
    const management = new ManagementClient({ domain: DOMAIN, clientId: CLIENT_ID, clientSecret: CLIENT_SECRET });
    
    try {
        await management.users.createAuthenticationMethod({id: USER_ID}, {type: "phone", phone_number: "USER_PHONE_NUMBER_FROM_PROFILE"});
    } catch (error) {
        ...
    }
  }
};

```

So basically If the user doesn’t have phone as the second factor I would create it with the phone number in their profile to challenge them for the current login.

I found out that even though the create authentication method succeed, the current universal login still doesn’t know about that just created method.

Im wondering what can I do to get it working.

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [March 11, 2025, 3:49pm UTC](https://community.auth0.com/t/change-mfa-factors-during-post-login-trigger/183660/3 "2025-03-11T15:49:45Z")

</div>

Hi @shawnyangkoho

Welcome to the Auth0 Community!

After you create or enroll the user to phone MFA as a second factor, you can use `api.authentication.challengeWith({type: 'phone'});` in order to force them to authenticate using it during the login.

As an alternative solution to your issue you could do the following:

```auto
if (!smsEnrolled) {
   api.authentication.enrollWith({type: 'phone'})
}

```

This way, the user will be prompted to enroll with SMS MFA on their login.

If you have any other questions, feel free to leave a reply!

Kind Regards,  
Nik

---

<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:** [March 25, 2025, 3:50pm UTC](https://community.auth0.com/t/change-mfa-factors-during-post-login-trigger/183660/4 "2025-03-25T15:50:22Z")

</div>

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