'Flutter firebase phonenumberauth how to get code
I use Firebase login to let the user use Facebook, but I also need to save the phone number using otp. So I do it as follows:
sendOtp() async {
print('otp call');
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: '+923323789263',
verificationCompleted: (PhoneAuthCredential credential) {},
verificationFailed: (FirebaseAuthException e) {},
codeSent: (String verificationId, int code) {
},
codeAutoRetrievalTimeout: (String verificationId) {},
);
}
OTP Code is going to the number but I need that code so I can match it with user input.
I have entered user otp to verify also like this
AuthCredential credential = PhoneAuthProvider.credential(
verificationId: verificationIdd,
smsCode: textEditingController.text.trim());
print(credential);
FirebaseAuth.instance.signInWithCredential(credential);
final User user = FirebaseAuth.instance.currentUser;
But i don't want to signin I need to just check that the use enter correct otp or not. I try to print credential but its showing same response for correct and wrong otp which is this
AuthCredential(providerId: phone, signInMethod: phone, token: null)
And it's not showing anything from which i can guess otp is correct or not.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
