sendVerificationCode method

void sendVerificationCode({
  1. String? phoneNumber,
  2. AuthAction action = AuthAction.signIn,
  3. int? forceResendingToken,
  4. MultiFactorSession? multiFactorSession,
  5. PhoneMultiFactorInfo? hint,
})

Sends an SMS code to the phoneNumber. If action is AuthAction.link, an obtained auth credential will be linked with the currently signed in user account. If action is AuthAction.signIn, the user will be created (if doesn't exist) or signed in.

Implementation

void sendVerificationCode({
  String? phoneNumber,
  AuthAction action = AuthAction.signIn,
  int? forceResendingToken,

  /// {@template ui.auth.providers.phone_auth_provider.mfa_session}
  /// Multi-factor session to use for verification
  /// {@endtemplate}
  fba.MultiFactorSession? multiFactorSession,

  /// {@template ui.auth.providers.phone_auth_provider.mfa_hint}
  /// Multi-factor session info to use for verification
  /// {@endtemplate}
  final fba.PhoneMultiFactorInfo? hint,
}) {
  final phone = phoneNumber ?? hint!.phoneNumber;
  authListener.onSMSCodeRequested(phone);

  if (kIsWeb) {
    _sendVerficationCodeWeb(phone, action);
  }

  auth.verifyPhoneNumber(
    forceResendingToken: forceResendingToken,
    phoneNumber: hint != null ? null : phoneNumber,
    multiFactorInfo: hint,
    multiFactorSession: multiFactorSession,
    verificationCompleted: authListener.onVerificationCompleted,
    verificationFailed: authListener.onError,
    codeSent: authListener.onCodeSent,
    codeAutoRetrievalTimeout: (_) {
      authListener.onError(AutoresolutionFailedException());
    },
  );
}