I’m trying to verify a phone number with Firebase when enrolling for Multi-Factor Authentication. I have a simple HTML and JavaScript app where I want to enable MFA for an already logged in user. That is, the user is not enrolling in MFA at login—they are enrolling through their profile at a later time. I’m following the instructions here:
https://cloud.google.com/identity-platform/docs/web/mfa
I can initialize the RecapatchVerifier successfully (step 3) and create a multiFactorSession (step 4) and initialize PhoneInfoOptions (step 5). However, when I try to verify the number with a PhoneAuthProvider (step 6), it throws an "auth/internal-error". I think this is because I'm not passing the right phone options (see below). Is the phoneNumber property deprecated? I can't find any other documentation on this that doesn't require a resolver hint (“[s]ign the user in with their first factor, then catch the auth/multi-factor-auth-required error. This error contains a resolver, hints on the enrolled second factors, and an underlying session proving the user successfully authenticated with the first factor.”), which I can't use because there is no error, I'm enrolling for the first time.
function twoFactor(new_phone) {
console.log("got the phone number, start enrolling in 2FA
");
multiFactor(user)
.getSession()
.then((multiFactorSession) => {
console.log('1')
// Is this the right object to use when enrolling a new MFA?
const phoneInfoOptions = {
phoneNumber: new_phone,
session: multiFactorSession
}
const phoneProvider = new PhoneAuthProvider(auth)
return phoneProvider.verifyPhoneNumber(phoneInfoOptions, recapatchaVerifier) //error happens on the return
// This promise creates an auth/internal-error
}).then(verificationId => {
console.log('2')
const credential = PhoneAuthProvider.credential(verificationId, window.prompt('Enter your code'))
const assertion = PhoneMultiFactorGenerator.assertion(credential)
return multiFactor(user).enroll(assertion)
})
}
Error: