updatePhoneNumber method

Future<void> updatePhoneNumber(
  1. PhoneAuthCredential phoneCredential
)

Updates the user's phone number.

A credential can be created by verifying a phone number via FirebaseAuth.signInWithPhoneNumber.

A FirebaseAuthException maybe thrown with the following error code:

  • invalid-verification-code
    • Thrown if the verification code of the credential is not valid.
  • invalid-verification-id
    • Thrown if the verification ID of the credential is not valid.

Implementation

Future<void> updatePhoneNumber(PhoneAuthCredential phoneCredential) async {
  _assertSignedOut(_auth);

  try {
    await _auth._api.smsAuth.confirmPhoneNumber(
      idToken: _idToken,
      smsCode: phoneCredential.smsCode,
      verificationId: phoneCredential.verificationId,
    );
    await reload();
  } catch (e) {
    rethrow;
  }
}