Describe the bug
If I try to set MFA type to NOMFA immediately after setting it to SMS or TOTP via Auth.setPreferredMFA, the preferred MFA method of the user doesn't change.
To Reproduce
Steps to reproduce the behavior:
SMS or TOTP via Auth.setPreferredMFA(user, "SMS")NOMFA via Auth.setPreferredMFA(user, "NOMFA")SMS (or TOTP)And I get the following error: No change for mfa type
Expected behavior
The MFA type should be set to NOMFA.
Desktop (please complete the following information):
After some research and debug, I noticed that the bug doesn't occur for a user that have already set hist MFA method to SMS or TOTP (the bug also doesn't occur anymore after sign out/sign in).
I also noticed that Auth.getPreferredMFA always returns the same MFA method.
So I inspected the source code and noticed that Auth.getPreferredMFA and Auth.setPreferredMFA call the user.getUserData method that try to get user data (and preferred MFA method) in the local storage!
So:
Auth.getPreferredMFA returns NOMFAHe sets his MFA method to SMS or TOTP
-> MFA method is successfully updated but the local storage isn't updated
-> Auth.getPreferredMFA returns NOMFA
He immediately sets his MFA method to NOMFA
-> Auth.setPreferredMFA(user, "SMS") try to get the current preferred MFA method in the local storage but local storage is empty
-> Auth.getPreferredMFA returns NOMFA
MFA method is always set to SMS (or TOTP) and we get the error No change for mfa type.
We can use the option bypassCache of the user.getUserData method to bypass local storage.
If you're ok with this, I can make a PR 馃槃
Could be related to https://github.com/aws-amplify/amplify-js/issues/2519 馃槈
I'm facing a lot of broken behavior that gets fixed by the bypassCache option. Without that option, updating MFA with TOTP/SMS is broken, updating the email is broken, etc. By broken, I mean performing a read after write always returns the old value, not the new value. With { bypassCache: true }, I receive the new value.
Thank you for the detailed report @Gautierrr !
A PR is always welcome 馃槃
Hello, I am having the same issue with Atuh.setPreferredMFA(user, 'SMS'), it says success when calling it but in cognito the user still has the MFA disabled and Auth.currentAuthenticatedUser({ bypassCache: true }) is not helping. I see there's a PR to add bypassCache to setPreferredMFA, but is there any other workaround to make it work in the meantime?
Most helpful comment
Thank you for the detailed report @Gautierrr !
A PR is always welcome 馃槃