f-miyu / Plugin.FirebaseAuth

MIT License
61 stars 26 forks source link

CrossFirebaseAuth.Current.PhoneAuthProvider.VerifyPhoneNumberAsync is always passing back VerificationId of null. #29

Open ashlar64 opened 3 years ago

ashlar64 commented 3 years ago

Hello,

I was doing some testing with two real phones. I logged into my app on phone A with phone B's phone number.

Now this line of code var verificationResult = await CrossFirebaseAuth.Current.PhoneAuthProvider.VerifyPhoneNumberAsync(CrossFirebaseAuth.Current.Instance, mobileNumber);

is always returning verificationResult.VerificationId as null when I used phone B's phone number on phone B. This was working fine before I did what I said above. I can still log into the app on phone A with phone A's phone number.

I actually deleted the Firebase account in the Firebase console for the phone number of phone B and this is still happening.

Any idea on what is going on? Is there anyway to reset this?

nnovalbos commented 3 years ago

I had the same problem. When upgrading the Xamarin.Firebase.Auth library from version 119.3.1 to 120.0.4 solved my problem.

nnovalbos commented 3 years ago

Hi, @ashlar64

Did you find a solution ??

I removed the error by updating the version, as I said in my previous comment, but when making the release version I get an error from the linker ...

LittleCornerDev commented 3 years ago

I have a similar issue wherein I use an Android device's own phone number to log in and VerifyPhoneNumberAsync() returns successfully each time, but the device only receives an SMS with a verification code the first time.

I found posts talking about Android "instant verification" and SMS "auto-retrieval", but I am unclear on when or why they would happen:

I tried to reduce timeout as per https://stackoverflow.com/questions/60208151/firebase-not-sending-verification-code-to-phone-the-second-time and deactivate "auto-retrieval" by setting timeout to 0 as per https://firebase.google.com/docs/reference/android/com/google/firebase/auth/PhoneAuthProvider#parameters_1 to no avail.

Uninstalling app and restarting device as per https://stackoverflow.com/questions/48536142/firebase-not-sending-otp also fixes nothing.

NOTE: The phone number is not whitelisted as a test number in Firebase settings in order to test real usage, so I am trying not to log in too often to prevent Firebase blocking the number. Test numbers can log in often but always come back with a VerificationId that is not null.

I saw a similar React plugin issue where the verification id is also null but that plugin's return object also says state is "Verified": https://github.com/invertase/react-native-firebase/issues/2895

My usage is currently:

I am wondering...

  1. Does a PhoneNumberVerificationResult where VerificationId == null always mean that the user is already verified? Is it safe to then to just log them in automatically? Should we save every credential we log in with in case we log in with different phone numbers from one device?
  2. Is there a way to access the forceResendingToken from this plugin? https://firebase.google.com/docs/reference/android/com/google/firebase/auth/PhoneAuthProvider#public-void-verifyphonenumber-string-phonenumber,-long-timeout,-timeunit-unit,-activity-activity,-phoneauthprovider.onverificationstatechangedcallbacks-callbacks,-phoneauthprovider.forceresendingtoken-forceresendingtoken
ashlar64 commented 3 years ago

FYI I have several different apps which use the same login system.

Rebooting the device seemed to usually help me. But I have now been avoiding using different phone numbers on different phones. The reason I even did this is because I could troubleshoot another account on my phone while debugging in in Visual Studio.

So no I really haven't found a solution.

LittleCornerDev commented 3 years ago

In case it helps anyone else following this issue, as I commented on my similar issue (https://github.com/f-miyu/Plugin.FirebaseAuth/issues/36), I got null PhoneNumberVerificationResult.VerificationId whenever an Android device automatically passed "instant verification" from a previous verification code. I was able to use the PhoneNumberVerificationResult.Credential instead to log user in.

My usage is now:

  1. Call VerifyPhoneNumberAsync() to get a PhoneNumberVerificationResult.
  2. Check PhoneNumberVerificationResult.VerificationId.
    • If PhoneNumberVerificationResult.VerificationId is not null:
      • Device should receive a verification code via SMS.
      • Pass user-typed verification code and PhoneNumberVerificationResult.VerificationId to GetCredential() get an IPhoneAuthCredential.
    • If PhoneNumberVerificationResult.VerificationId is null:
      • Device will not receive a verification code via SMS.
      • There should be an IPhoneAuthCredential returned in PhoneNumberVerificationResult.Credential.
  3. Pass the IPhoneAuthCredential to SignInWithCredentialAsync() to log user in.