BUG: UpdateUser() is not able to update MFA
brokeyourbike opened this issue · comments
Describe your environment
- Operating System version: Mac OS Ventura 13.0.1
- Firebase SDK version: Firebase Admin SDK v4
- Library version: v4.10.0
- Firebase Product: auth
Describe the problem
It's not possible to update multi factor enrollments with UpdateUser()
function. Create and update API requests have different structure when we speaking about MFA (don't know who thought it will be cool to do that). It's also not required to pass fields like UID
or DisplayName
when updating or creating MFA.
We can see the valid implementation in the firebase-admin-node repository
Steps to reproduce:
- Create user (or have existing firebase user) without MFA
- Try to add MFA with
UpdateUser
- Nothing will happen, used will not have MFA after update
Relevant Code:
// 1. Create user
createParams := (&auth.UserToCreate{}).
UID("01GM6YCBT7T0VNPNTCP44S7E8G").
Email("john@doe.com").
EmailVerified(true).
Password("secret").
DisplayName("John Doe").
Disabled(false).
MFASettings(auth.MultiFactorSettings{EnrolledFactors: nil})
user, err := firebaseAuth.CreateUser(ctx, params)
require.NoError(t, err)
// 2. Update user
updateParams := (&auth.UserToUpdate{}).
MFASettings(auth.MultiFactorSettings{
EnrolledFactors: []*auth.MultiFactorInfo{{
// problems will arise even on this stage
// because library things that it's required to pass UID and DisplayName
FactorID: "phone",
PhoneNumber: "+16505557348",
}},
})
user, err = firebaseAuth.UpdateUser(ctx, user.UID, params)
assert.NoError(t, err)
assert.Len(t, user.MultiFactor.EnrolledFactors, 1)