verifyPhoneNumber method

Future<void> verifyPhoneNumber(
  1. {String? phoneNumber,
  2. PhoneMultiFactorInfo? multiFactorInfo,
  3. required PhoneVerificationCompleted verificationCompleted,
  4. required PhoneVerificationFailed verificationFailed,
  5. required PhoneCodeSent codeSent,
  6. required PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout,
  7. @visibleForTesting String? autoRetrievedSmsCodeForTesting,
  8. Duration timeout = const Duration(seconds: 30),
  9. int? forceResendingToken,
  10. MultiFactorSession? multiFactorSession}
)

Starts a phone number verification process for the given phone number.

This method is used to verify that the user-provided phone number belongs to the user. Firebase sends a code via SMS message to the phone number, where you must then prompt the user to enter the code. The code can be combined with the verification ID to create a PhoneAuthProvider.credential which you can then use to sign the user in, or link with their account ( see signInWithCredential or linkWithCredential).

On some Android devices, auto-verification can be handled by the device and a PhoneAuthCredential will be automatically provided.

No duplicated SMS will be sent out unless a forceResendingToken is provided.

phoneNumber The phone number for the account the user is signing up for or signing into. Make sure to pass in a phone number with country code prefixed with plus sign ('+'). Should be null if it's a multi-factor sign in.

multiFactorInfo The multi factor info you're using to verify the phone number. Should be set if a multiFactorSession is provided.

multiFactorSession The multi factor session you're using to verify the phone number. Should be set if a multiFactorInfo is provided.

timeout The maximum amount of time you are willing to wait for SMS auto-retrieval to be completed by the library. Maximum allowed value is 2 minutes.

forceResendingToken The forceResendingToken obtained from codeSent callback to force re-sending another verification SMS before the auto-retrieval timeout.

verificationCompleted Triggered when an SMS is auto-retrieved or the phone number has been instantly verified. The callback will receive an PhoneAuthCredential that can be passed to signInWithCredential or linkWithCredential.

verificationFailed Triggered when an error occurred during phone number verification. A FirebaseAuthException is provided when this is triggered.

codeSent Triggered when an SMS has been sent to the users phone, and will include a verificationId and forceResendingToken.

codeAutoRetrievalTimeout Triggered when SMS auto-retrieval times out and provide a verificationId.

Implementation

Future<void> verifyPhoneNumber({
  String? phoneNumber,
  PhoneMultiFactorInfo? multiFactorInfo,
  required PhoneVerificationCompleted verificationCompleted,
  required PhoneVerificationFailed verificationFailed,
  required PhoneCodeSent codeSent,
  required PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout,
  @visibleForTesting String? autoRetrievedSmsCodeForTesting,
  Duration timeout = const Duration(seconds: 30),
  int? forceResendingToken,
  MultiFactorSession? multiFactorSession,
}) {
  assert(
    phoneNumber != null || multiFactorInfo != null,
    'Either phoneNumber or multiFactorInfo must be provided.',
  );
  return _delegate.verifyPhoneNumber(
    phoneNumber: phoneNumber,
    multiFactorInfo: multiFactorInfo,
    timeout: timeout,
    forceResendingToken: forceResendingToken,
    verificationCompleted: verificationCompleted,
    verificationFailed: verificationFailed,
    codeSent: codeSent,
    codeAutoRetrievalTimeout: codeAutoRetrievalTimeout,
    // ignore: invalid_use_of_visible_for_testing_member
    autoRetrievedSmsCodeForTesting: autoRetrievedSmsCodeForTesting,
    multiFactorSession: multiFactorSession,
  );
}