verifyPhoneNumber method
- String? phoneNumber,
- PhoneMultiFactorInfo? multiFactorInfo,
- required PhoneVerificationCompleted verificationCompleted,
- required PhoneVerificationFailed verificationFailed,
- required PhoneCodeSent codeSent,
- required PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout,
- String? autoRetrievedSmsCodeForTesting,
- Duration timeout = const Duration(seconds: 30),
- int? forceResendingToken,
- 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 ('+').
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
@override
Future<void> verifyPhoneNumber({
String? phoneNumber,
PhoneMultiFactorInfo? multiFactorInfo,
required PhoneVerificationCompleted verificationCompleted,
required PhoneVerificationFailed verificationFailed,
required PhoneCodeSent codeSent,
required PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout,
String? autoRetrievedSmsCodeForTesting,
Duration timeout = const Duration(seconds: 30),
int? forceResendingToken,
MultiFactorSession? multiFactorSession,
}) async {
try {
Map<String, dynamic>? data;
if (multiFactorSession != null) {
final _webMultiFactorSession =
multiFactorSession as MultiFactorSessionWeb;
if (multiFactorInfo != null) {
data = {
'multiFactorUid': multiFactorInfo.uid,
'session': _webMultiFactorSession.webSession.jsObject,
};
} else {
data = {
'phoneNumber': phoneNumber,
'session': _webMultiFactorSession.webSession.jsObject,
};
}
}
final phoneOptions = (data ?? phoneNumber)!;
final provider = auth_interop.PhoneAuthProvider(_webAuth);
final verifier = RecaptchaVerifierFactoryWeb(
auth: this,
).delegate;
/// We add the passthrough method for LegacyJsObject
final verificationId =
await provider.verifyPhoneNumber(phoneOptions.jsify(), verifier);
codeSent(verificationId, null);
} catch (e) {
verificationFailed(getFirebaseAuthException(e));
}
}