-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[firebase_auth] Unhandled Exception: PlatformException(ERROR_INVALID_VERIFICATION_CODE) #3141
Comments
Can you try the below syntax |
Here's what I did void signInWithPhone(String phone) {
// your firebase calls
// Authenticate user with Firebase
FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: "+XXX XXX XX XXXX",
timeout: Duration(seconds: 60),
codeSent: (verificationId, [int token]) {
// Perform action
// Navigate to another screen & input CODE
},
codeAutoRetrievalTimeout: (verificationId) {},
verificationCompleted: (credentials) => null,
verificationFailed: (ex) => print("$ex"),
);
...
}
void verifyCode(String verificationId, String code) async {
try {
var firebaseUser = await FirebaseAuth.instance.currentUser();
final credential = PhoneAuthProvider.getCredential(verificationId: verificationId, smsCode: code);
firebaseUser.updatePhoneNumberCredential(credential);
} on PlatformException catch (e) {
print("Exception caught => ${e.code}");
}
}
// Call function "verifyCode" somewhere with an invalid verification code
verifyCode("---------", "WRONG CODE") And it still throws the exception |
Hey 👋 Our rework of the See: https://firebase.flutter.dev/docs/auth/error-handling For help migrating to the new plugins please see the new migration guide: https://firebase.flutter.dev/docs/migration |
Having updated my version of New Example: try {
// Authenticate user using existing phone number credential
final credential = PhoneAuthProvider.getCredential(verificationId: '-------', smsCode: 'VALID CODE');
firebaseUser.updatePhoneNumberCredential(credential);
} catch (e) {
// The exception is not caught here
print("Exception caught => $e");
} |
Describe the bug
I cannot handle the above exception using
try / catch
when an invalid SMS verification code is passed to thefirebaseUser.updatePhoneNumberCredential(credential)
methodTo Reproduce
Steps to reproduce the behavior:
Expected behavior
The
try / catch
block should handle the exception rather than rethrowing / ignoring it.In my case, a debug print in the console with the exception ->
Flutter doctor
Run
flutter doctor
and paste the output below:The text was updated successfully, but these errors were encountered: