Resending SMS using "forceResendingToken" on verifyPhoneNumber
I can't seem to figure out how to resend a SMS if the first one was lost or not received.
I dug into verifyPhoneNumber and found forceResendingToken but I couldn't find any documentation on how to use or apply it.
Some guidance would be much apprecited.
/// [forceResendingToken] The [forceResendingToken] obtained from [codeSent]
/// callback to force re-sending another verification SMS before the
/// auto-retrieval timeout.
Same issue here. Been trying to figure it out for almost 5 hours now.
Hi @anraiki @JemZubiri-Projects
Please check this Stackoverflow answer and you can find PhoneCodeSent api
Hope it helps Thanks
@TahaTesser Hi Taha, that answer and solution leads back to this: https://pub.dev/documentation/firebase_auth/latest/firebase_auth/FirebaseAuth/verifyPhoneNumber.html
Which still does not explain properly how to use forceResendingToken.
The PhoneCodeSent executes after an SMS is sent but I am trying to do a manual resend in case the user finds that they have not received their code.
Need this ASAP. Please provide an explanation on how to use it because that was our problem.
It's time for discovery!
I believe our next step is to hold onto the forceResendingToken and drop it into verifyPhoneNumber and call it again.
This should essentially rerun the function again and send the sms once more and loop back to the verification screen.
Tried that and there are times that the OTP is not resending. Maybe because the timeout is not yet called?
If yours is working stably, can you please show me how you did yours? Thank you
Seems to be working for me. It sent the same SMS code 3x from the same text services.
await _auth.verifyPhoneNumber(
phoneNumber: "+1$truePhoneNumber",
timeout: const Duration(seconds: 5),
forceResendingToken: _forceResendingToken,
verificationCompleted: (AuthCredential phoneAuthCredential) async {
await _auth.signInWithCredential(phoneAuthCredential);
final FirebaseUser currentUser = await _auth.currentUser();
if( currentUser.uid.isNotEmpty ) {
await _pushSignIn(currentUser);
} else {
print("Could not get Current User");
}
},
verificationFailed: (AuthException authException) {
print('Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}');
_alertError('There was an error in sending the code. Please contact us to help you sort this issue.');
return;
},
codeSent: (String verificationId, [int forceResendingToken]) async {
setState(() {
_loading = false;
});
_verificationId = verificationId;
_forceResendingToken = forceResendingToken;
},
codeAutoRetrievalTimeout: (String verificationId) {
// print("Time Out. Duration Exceeded");
_verificationId = verificationId;
}
);