Firebase OTP verfiicationCompleted method does not work in latest firebase auth plugin flutter

Viewed 39

I'm using firebase auth for phone number verification in my flutter project, it works fine as it sends the OTP code to the device but verificationcompleted method which autoverifies the phone number does not call at all. I have followed all the configuration setups, Device verification api is enabled in Google cloud console. Now i am not sure if the firebase removed this autoverified or not because i did not find anything about it in their documentaion, Here is the code to get OTP Code.

Future getPinCode() async {
print("Starting OTP process");
_auth.verifyPhoneNumber(
  phoneNumber:
      "+92${phoneNumber.toString()}",
  timeout: const Duration(seconds: 60),
  verificationCompleted: _verificationCompleted,
  verificationFailed: _verificationFailed,
  codeSent: _codeSent,
  codeAutoRetrievalTimeout: _codeAutoRetrievalTimeout,
);
}

_verificationCompleted(PhoneAuthCredential authCredential) {
log("verificationCompleted ");
_auth.signInWithCredential(authCredential).then((UserCredential result) {
  Get.to(() => const HomePage());
}).catchError((e) {
  log(e);
});
}

here in verificationcompleted Im signing user and navigating to homePage, but this method never gets called

_verificationFailed(FirebaseAuthException authException) {
print(authException.message);
}
 _codeSent(String verificationId, int? resendToken) async {
log("codeSent $verificationId");
verificationCode =
    verificationId; // Update the UI - wait for the user to enter the SMS code
//String smsCode = 'xxxx';

// Create a PhoneAuthCredential with the code
//PhoneAuthCredential credential = PhoneAuthProvider.credential(verificationId: verificationId, smsCode: smsCode);

// Sign the user in (or link) with the credential
//await _auth.signInWithCredential(credential);
}

 _codeAutoRetrievalTimeout(String verificationId) {
verificationCode = verificationId;

log("Timout");
}  

output Log (1)

output Log (2)

0 Answers
Related