linkWithPhoneNumber method

Future<ConfirmationResult> linkWithPhoneNumber(
  1. String phoneNumber, [
  2. RecaptchaVerifier? verifier
])

Links the user account with the given phone number.

This method is only supported on web platforms. Use verifyPhoneNumber and then linkWithCredential on these platforms.

A FirebaseAuthException maybe thrown with the following error code:

  • provider-already-linked:
  • Thrown if the provider has already been linked to the user. This error is thrown even if this is not the same provider's account that is currently linked to the user.
  • captcha-check-failed:
  • Thrown if the reCAPTCHA response token was invalid, expired, or if this method was called from a non-whitelisted domain.
  • invalid-phone-number:
  • Thrown if the phone number has an invalid format.
  • quota-exceeded:
  • Thrown if the SMS quota for the Firebase project has been exceeded.
  • user-disabled:
  • Thrown if the user corresponding to the given phone number has been disabled.
  • credential-already-in-use:
  • Thrown if the account corresponding to the phone number already exists among your users, or is already linked to a Firebase User.
  • operation-not-allowed:
  • Thrown if you have not enabled the phone authentication provider in the Firebase Console. Go to the Firebase Console for your project, in the Auth section and the Sign in Method tab and configure the provider.

Implementation

Future<ConfirmationResult> linkWithPhoneNumber(
  String phoneNumber, [
  RecaptchaVerifier? verifier,
]) async {
  assert(phoneNumber.isNotEmpty);
  // If we add a recaptcha to the page by creating a new instance, we must
  // also clear that instance before proceeding.
  bool mustClear = verifier == null;
  verifier ??= RecaptchaVerifier(auth: _delegate.auth);
  final result =
      await _delegate.linkWithPhoneNumber(phoneNumber, verifier.delegate);
  if (mustClear) {
    verifier.clear();
  }
  return ConfirmationResult._(_auth, result);
}