FirebaseAuthEx - Extends FirebaseAuth functionality

DonManfred

Expert
Licensed User
Longtime User
This is a wrap to extend the functionality of FirebaseAuth.
It adds Anonymously Authentification and Email and Password Authentification

The Library is similar to FirebaseAuth (the Events). Ony difference is that the FirebaseUser is here a FiebaseAuthUser. A different object than the userobject from FirebaseAuth.
The FirebaseAuthUser has someproperties and Methods more.

FirebaseAuthEx
Version:
1.13
  • FirebaseAuthEx
    Events:
    • SignedIn (User As FirebaseUser)
    • UserCreated (User As FirebaseUser)
    Methods:
    • Initialize (EventName As String)
      Initializes the object. The SignedIn event will be raised if there is already a signed in user.
    • SignInWithEmailAndPassword (email As String, password As String)
    • SignOut
      Sign outs from Firebase and Google.
    • createUserWithEmailAndPassword (email As String, password As String)
    • sendPasswordResetEmail (email As String)
    • signInAnonymously
    Properties:
    • CurrentUser As FirebaseAuthUserWrapper [read only]
      Returns the current signed in user. Returns an uninitialized object if there is no user.
  • FirebaseAuthUser
    Methods:
    • IsInitialized As Boolean
    • delete
    • sendEmailVerification
    • updateEmail (email As String)
    • updatePassword (password As String)
    Properties:
    • Anonymous As Boolean [read only]
    • DisplayName As String [read only]
    • Email As String [read only]
    • EmailVerified As Boolean [read only]
    • PhotoUrl As String [read only]
    • ProviderData As List [read only]
    • ProviderId As String [read only]
    • Providers As List [read only]
    • Uid As String [read only]
 

Attachments

  • FirebaseAuthExV1.12.zip
    8.3 KB · Views: 395
  • FirebaseAuthExV1.13.zip
    8.4 KB · Views: 386
  • FirebaseAuthExV1.14.zip
    11.9 KB · Views: 640
Last edited:

fredo

Well-Known Member
Licensed User
Longtime User
...to extend the functionality of FirebaseAuth...

Thank you Don!

For those who are interested in learning about Firebase Auth & Database I thought I make my own testproject available (see attachment).

B4X:
    '   1. Make sure to have YOUR package name [Ctl+B] in your "Firebase Project settings"  https://console.firebase.google.com/project
    '   2. Make sure to have YOUR "google-services.json" file in your B4A project folder
    '   3. Make sure to have YOUR strFirebaseProjectId in the "Starter" module (replace "myid-abc1111" with yout project-id)
    '   4. While using this project always have this two windows open: a) Logs, b) Firebase console/Database/DATA

Get a grip on the Firebase:
12-10-_2016_14-42-29.jpg



Watch what happens in the Log:
12-10-_2016_14-43-33.jpg


Useful Firebase console parts:
12-10-_2016_14-46-44.jpg
 

Attachments

  • fredo_FiBaDb_tester_16s.zip
    83.1 KB · Views: 475
Last edited:

DonManfred

Expert
Licensed User
Longtime User
did you had a chance to work on the lib?
you can just change your subs signature to use FirebaseAuthUser instead of FirebaseUser then it should work
the suggested signature is wrong. it will be fixed in next version
 

fredo

Well-Known Member
Licensed User
Longtime User
...just change your subs signature...
Worked. Thank you.

New effect while trying to "SignUp" a new eMail user:
B4X:
Dim authx As FirebaseAuthEx

'...
authx.Initialize("authx")
'...

Sub button_sign_up_Click
    authx.createUserWithEmailAndPassword("[email protected]", "foo123")
End Sub

Sub authx_UserCreated(User As  FirebaseAuthUser)  ' <--tried also "FirebaseUser", but that type misses: .Anonymous, .EmailVerified, .ProviderData, .ProviderId, .Providers
  '... throws error message (see below)
End Sub

B4X:
java.lang.Exception: Sub authx_usercreated signature does not match expected signature.
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:171)
   at anywheresoftware.b4a.BA$2.run(BA.java:328)
   at android.os.Handler.handleCallback(Handler.java:751)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6077)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
 

alimanam3386

Active Member
Licensed User
Longtime User
Hi

When we use bellow function for sign in , how can we handle sign in function was successful ( email and password was registered ) or not ?

B4X:
Starter.AuthEx.SignInWithEmailAndPassword(txtEmail.Text , txtPassword.Text)

I know we have bellow event

B4X:
Sub AuthEx_SignedIn(User As FirebaseAuthUser)

    If User.IsInitialized Then
        ToastMessageShow("OK Welcome !" , False)
    Else
        ' This line of code will not run ! why ?
        ToastMessageShow("Email or password invalid !" , False)
    End If

End Sub

' And also this event never run ( when we use createUserWithEmailAndPassword function )
Sub AuthEx_UserCreated(User As FirebaseAuthUser)
    ToastMessageShow("New User Registered in db successfuly" , False)
End Sub

If we use signin function how aware that was success or not ????

And also when we use createUserWithEmailAndPassword function same problem ! The event of that function not happen!!!!
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
But when the login action was not successful how can we know that was not successful ????
The given user does contain all infos needed. Check the Properties.

B4X:
@ShortName("FirebaseAuthUser")
    public static class FirebaseAuthUserWrapper extends AbsObjectWrapper<FirebaseUser> {
        public boolean getAnonymous() {
            return getObject().isAnonymous();
        }
        public void updateEmail(String email) {
            getObject().updateEmail(email);
        }
        public void delete() {
            getObject().delete();
        }
        public void updatePassword(String password) {
            getObject().updatePassword(password);
        }
        public void sendEmailVerification() {
            getObject().sendEmailVerification();
        }
        public boolean getEmailVerified() {
            return getObject().isEmailVerified();
        }
        public String getEmail() {
            return getObject().getEmail();
        }
        public String getDisplayName() {
            return getObject().getDisplayName();
        }
        public String getUid() {
            return getObject().getUid();
        }
        public String getProviderId() {
            return getObject().getProviderId();
        }
        public List<String> getProviders() {
            return getObject().getProviders();
        }
        public List<? extends UserInfo> getProviderData() {
            return getObject().getProviderData();
        }
        public String getPhotoUrl() {
            return getObject().getPhotoUrl() == null ? "" : getObject().getPhotoUrl().toString();
        }
       
    }
 

alimanam3386

Active Member
Licensed User
Longtime User
The given user does contain all infos needed. Check the Properties.

Hi Dear DonManfred

Yes I know that but I can't handle invalid login . If you try to know an user is valid (Email & Password are correct ) you must use bellow code
B4X:
Starter.AuthEx.SignInWithEmailAndPassword(txtEmail.Text , txtPassword.Text)

I think the SignedIn EVENT should has a parameter more like this

B4X:
Sub AuthEx_SignedIn(User As FirebaseAuthUser, Success as Boolean)
If Success Then
' do somethings
Else
' Here we can do some things ..... ex: Show a alert box or notify
End If
End Sub

If user info ( email & password ) was valid anything will be OK .....
BUT IF that login info ( Email or Password ) was not correct , How aware that ? this is my question.


20j1u0p.jpg


Thank you
 
Last edited:

alimanam3386

Active Member
Licensed User
Longtime User
ah, ok. Now i understand.
Hmmm... Did you see something like "signInWithEmail:failed" in your log when trying to use wrong credentials?

I guess i´ll add a fallback event in case of a unsuccessfull login now as i´m reviewing the code


And Please check the " AuthEx_UserCreated " EVENT . when you create new user by " createUserWithEmailAndPassword " Function , The Event for UserCreated NOT work correctly .

Cheers Man :)
 
Last edited:
Top