B4A Library Firebase phone number authentication

Enrico Fuoti

Member
Licensed User
Here is my second lib, a wrap to integrate firebase auth phone number authentication.
It is working nicely on my app.
for reference visit: Authenticate with Firebase on Android using a Phone Number

FirebaseAuthPhone
Version: 1.1

Events:

  • phoneverification (success As Boolean, info As String)
  • phonesignedin (success As Boolean, User As FirebaseAuthPhoneUser, info As String)
  • oncodesent (success As Boolean, verificationid As String)
Methods:
  • Initialize (eventName As String)
  • startPhoneNumberVerification (phoneNumber As String)
  • verifyPhoneNumberWithCode (verificationId As String, code As String)
  • SignOut

Properties:
  • CurrentUser As FirebaseAuthPhoneUserWrapper [read only]


FirebaseAuthPhoneUser

Properties:

  • Anonymous As Boolean [read only]
  • IsInitialized As Boolean [read only]
  • ProviderData As List [read only]
  • ProviderId As String [read only]
  • Providers As List [read only]
  • Uid As String [read only]
 

Attachments

Last edited:

hypergreatthing

Member
Licensed User
I'm having an issue when manually entering a sms authentication code that's wrong. I get a crash:
B4X:
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user.

    at com.google.android.gms.tasks.zzu.getResult(com.google.android.gms:play-services-tasks@@17.2.0:15)

    at anywheresoftware.b4a.FirebaseAuthPhone.FirebaseAuthPhoneWrapper$3.onComplete(FirebaseAuthPhoneWrapper.java:338)



...

Caused by: com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user.
 

Enrico Fuoti

Member
Licensed User
I'm having an issue when manually entering a sms authentication code that's wrong. I get a crash:
B4X:
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user.

    at com.google.android.gms.tasks.zzu.getResult(com.google.android.gms:play-services-tasks@@17.2.0:15)

    at anywheresoftware.b4a.FirebaseAuthPhone.FirebaseAuthPhoneWrapper$3.onComplete(FirebaseAuthPhoneWrapper.java:338)



...

Caused by: com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user.
Hello Hyper,
In most cases verification code is automatically verified by the system.. so i didn't actually tested the manual code insertion page.
All the phones i tried sent the code received by sms and verified automatically.
It looks like the wrapper code correctly receives the exception by Firebase in the callback event.
Did you try debugging b4a to check if the
sub authphone_phonesigned (success As Boolean, User As FirebaseAuthPhoneUser, info As String)
event is triggered ?
 

hypergreatthing

Member
Licensed User
Hello Hyper,
In most cases verification code is automatically verified by the system.. so i didn't actually tested the manual code insertion page.
All the phones i tried sent the code received by sms and verified automatically.
It looks like the wrapper code correctly receives the exception by Firebase in the callback event.
Did you try debugging b4a to check if the
sub authphone_phonesigned (success As Boolean, User As FirebaseAuthPhoneUser, info As String)
event is triggered ?
Yes. I have both _phonesignedin event and _phoneverification with break points after manually entering an incorrect sms. Neither are triggered, it just crashes straight away.
 

hypergreatthing

Member
Licensed User
I'm not able to replicate the issue,
Try this.
let me know.
That didn't seem to fix the crash.
Give me some time and i'll create a sample program that's cut down to just the issue.
Long story short, i'm developing an app that's to be deployed in Africa. For whatever reason the local telco is supplying odd sim cards that in android phones, show up as unknown phone numbers. In order to determine the phone number they have to sent a * code to the telco and it responds back with their phone number.
Because of this, i put in some logic so when PhoneID.GetLine1Number returns a empty string, it pulls up a screen that asks them to enter in the phone number manually.
Once they submit the number, i call authphone.startPhoneNumberVerification(phoneNumber). That seems to work perfectly fine and an sms is sent from firebase with the code.
If i enter in the code correctly everything works, it advances to the next screen. However if i enter in the wrong code (55555,etc) i get the crash.
I am able to replicate the same behavior with a 2nd phone i have if i pull the sim card with it returning an empty string for the GetLine1Number function.
I am using b4a 10.2 and android-28 as the platform.
 

hypergreatthing

Member
Licensed User
Hyper,
I may have found where the problem is. try this one.
Still crashes.
I'm attaching a sample program.
It should ask you to enter in your phone number. I suggest putting in an alternate number to get the code on another phone.
If you enter the code correctly in the next screen correctly you will log in without issue.
If you enter in the wrong code on purpose, a crash occurs.
I created a separate firebase app/keystore/etc so it should be all good to compile as is
 

Attachments

Top