Remove previous callbacks for wrong number entered.
Step 1: Are you in the right place?
Yes.
Step 2: Describe your environment
- Android device: Any
- Android OS version: Any
- Google Play Services version: 11.8.0
- Firebase/Play Services SDK version: 11.8.0
- FirebaseUI version: 3.2.1
Step 3: Describe the problem:
Steps to reproduce:
- Enter wrong number.
- Enter another wrong number again.
- Enter correct number.
- Wait for the Sms auto fill. First it shows 'Wrong code entered' and then logs in.
Observed Results:
It generates 3 different callbacks for onVerificationCompleted for the first two callbacks signInWithCredential fails due to wrong number and it goes to success for the last one.
Expected Results:
It should auto cancel all previous callbacks or there should a way to cancel previous callbacks.
Can you try with FUI v4.1.0? We fixed tons of bugs in that area.
I'll get back to you asap after trying FUI 4.1.0
@SUPERCILEX Issue persists in FUI v4.1.0. Just tested.
@SUPERCILEX I think this is a Firebase Auth issue, not a Firebase UI issue.
I have made my own Firebase Authentication UI and I also face this issue. The OnVerificationStateChangedCallbacks get called for older, incorrect verification attempts, upon a correct attempt eventually.
I suspect the problem is with FirebaseAuth itself. Can others please confirm?
Trying to understand exactly what's going on here: are you saying that you get a bunch of OnVerificationStateChangedCallbacks all at once after the end of a series of requests?
Hi @samtstern, think I can answer this (pls correct me if I misrepresented the problem, @abdulwasae).
Here is the sequence of steps:
- A user enters their phone number.
- The app then calls
verifyPhoneNumberon an instance of the FirebasePhoneAuthProvider. - The user realizes they entered the wrong phone number. So the user goes back and enters their phone number again.
- The app calls
verifyPhoneNumberagain, with the new phone number. There is no way to cancel the oldverifyPhoneNumberrequest - User receives an SMS code, which is automatically read by Firebase.
- THE PROBLEM: The first
verifyPhoneNumberrequest triggers theonVerificationFailedcallback, for the first (incorrect) number entered. - The second
verifyPhoneNumberrequest triggers theonVerificationCompletedcallback.
Steps 6 and 7 are where we see the problem. Ideally, Firebase PhoneAuth does not try to use the same code to verify two different numbers. Instead, Firebase should allow us to cancel the first verification request. Even better, Firebase should cancel the first verification request as soon as the app tries to verify a second number, so that at any given time only one verification callback is triggered.
I hope this clears up the issue.
@ismail-a-khan thanks for the very detailed steps! This sounds like a bug I should file with the Firebase Auth folks. Because this is not a FirebaseUI issue I will close it here, but I will come back to this thread and update once I hear back from the Firebase Auth engineering team.
@samtstern, I think you might want to consider patching this in Firebase UI as well. You can work around the Firebase auth issue by doing the following:
- Keep track of the 'current' phone number to verify, perhaps in an instance variable.
- Immediately before you call
verifyPhoneNumber(in the same method where you call it), save the 'current' phone number in afinallocal variable. Each callback can now reference a snapshot of the phone number that is being verified. - In the
onVerificationCompletedmethod of theOnVerificationStateChangedCallbacksobject that is passed toverifyPhoneNumber, check if the actual 'current' phone number to verify is equal to the phone number that was captured/enclosed by the callback object -- if the number's don't match, stop execution. Do the same inonVerificationFailedas well.
This should solve the problem, because now each OnVerificationStateChangedCallbacks is aware of which number it is trying to verify. By comparing the callback object's own number to the actual number that we want to verify, we can ignore all the callbacks that are associated with old numbers.
It's a bit of a hack, sure, but will at least solve the problem until the Firebase Auth team fixes the issue (which may take ages, given my experience with Cloud Firestore bugs...). If my explanation is not clear I could go ahead and submit a PR of the fix.
Btw, I was slightly incorrect in my steps-to-recreate above. In step #6, it is actually onVerificationCompleted that is called, not onVerificationFailed, such that onVerificationCompleted is called twice overall. The fix is the same either way.
Thanks @ismail-a-khan you are right, we could fix this here as well.
@samtstern Any update on the bug from Firebase Auth?
@samtstern Having the same issue with those callbacks, any progress? Any updates?