f-miyu / Plugin.FirebaseAuth

MIT License
61 stars 26 forks source link

Not receiving verification code after the first phone login on Android and unable to save credentials #36

Closed LittleCornerDev closed 3 years ago

LittleCornerDev commented 3 years ago

Related to my comment/question on https://github.com/f-miyu/Plugin.FirebaseAuth/issues/29.

Due to null verification id, presumably because of "instant verification", it seems verification code is never sent to Android device again after the first time it is sent.

I am trying to save the IAuthCredential from the initial successful login with Xamarin.Essentials.SecureStorage in attempt to re-use it when the verification id comes back as null. However, deserializing the data into a string errors with "Error getting value from Provider" when using Newtonsoft.Json.JsonConvert.DeserializeObject<T>() and "deserialization of interface types is not supported" when using System.Text.Json.JsonSerializer.Deserialize<T>().

I tried using PhoneAuthCredentialWrapper as the data type instead of IAuthCredential, but PhoneAuthCredentialWrapper "does not exist in the namespace".

I hear it is possible to write a custom JSON converter, but it has to be annotated in the concrete class implementation: https://www.c-sharpcorner.com/UploadFile/20c06b/deserializing-interface-properties-with-json-net/

Please advise. How have people successfully implemented logging in by phone more than once with a real phone number on an Android device? Is it possible to access PhoneAuthCredentialWrapper? Do I need to write my own custom wrapper class? If so, how can it inherit from PhoneAuthCredentialWrapper if it is inaccessible?

LittleCornerDev commented 3 years ago

Alternatively, is there a way to disable instant verification with this plugin? How do we stop getting null verification id from VerifyPhoneNumberAsync()?

LittleCornerDev commented 3 years ago

https://firebase.google.com/docs/auth/android/phone-auth has a code comment that mentions "Instant verification is applied and a credential is directly returned."

I then realized https://github.com/f-miyu/Plugin.FirebaseAuth/blob/master/Plugin.FirebaseAuth/Shared/PhoneNumberVerificationResult.cs returns an optional Credential I can use to log in when VerificationId is null.

Closing this issue.