I am trying to verify phone number using firebase. But getting unexpected result from async function. Here is my code :
bool isVerificationSuccess = false;
Future<bool> verifyUserPhoneNumber(String phoneNumber) async {
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: Duration(seconds: 60),
verificationCompleted: (credential) => verificationComplete(credential),
verificationFailed: (authException) => verificationFailed(authException),
codeAutoRetrievalTimeout: (verificationId) =>
codeAutoRetrievalTimeout(verificationId),
codeSent: (verificationId, [code]) => smsCodeSent(verificationId, [code]),
);
print("Status from service : $isVerificationSuccess");
return isVerificationSuccess;
}
verificationComplete(AuthCredential credential) async {
FirebaseUser user = await FirebaseAuth.instance.currentUser();
user.linkWithCredential(credential).then((_) {
print("User Successfully Linked");
isVerificationSuccess = true;
}).catchError((e) {
print("Linking Error : ${e.toString()}");
});
}
Here is the output :
Status from service : false
User Successfully Linked
So here verifyUserPhoneNumber function returns even before the completion of FirebaseAuth.instance.verifyPhoneNumber(), so its not returning expected data (always false) even when the verification is successful. Whats wrong here?