Android Question Firebase auth: method - createuserwithemailAndPassword

Robert_Rm

Member
Licensed User
I have problems with Firebase when creating a new user: method - createuserwithemailAndPassword
I get an error.
Can someone help me?
Error log:

Installing file.
PackageAdded: package:com.login.android
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
firsttime _ ok
** Activity (main) Resume **
resume
resume
** Activity (main) Pause, UserClosed = false **
** Activity (test_post_error) Create, isFirst = true **
** Activity (test_post_error) Resume **
createUserWithEmail:eek:nComplete:false
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account.
at com.google.android.gms.tasks.zzh.getResult(Unknown Source)
at de.donmanfred.FirebaseAuthExWrapper$4.onComplete(FirebaseAuthExWrapper.java:155)
at com.google.android.gms.tasks.zzc$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account.
at com.google.android.gms.internal.zzbix.zzcb(Unknown Source)
at com.google.android.gms.internal.zzbiu$zzj.zza(Unknown Source)
at com.google.android.gms.internal.zzbjf.zzcc(Unknown Source)
at com.google.android.gms.internal.zzbjf$zza.onFailure(Unknown Source)
at com.google.android.gms.internal.zzbja$zza.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:453)
 
Last edited:

npsonic

Active Member
Licensed User
This is still a problem. If user is already authenticated and "createUserWithEmailAndPassword" is used with same email the app will crash.
Crash will happen even with the Try Catch

B4X:
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account.
    at com.google.android.gms.tasks.zzu.getResult(Unknown Source:30)
    at de.donmanfred.FirebaseAuthExWrapper$4.onComplete(FirebaseAuthExWrapper.java:155)
    at com.google.android.gms.tasks.zzj.run(Unknown Source:32)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6809)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account.
    at com.google.firebase.auth.api.internal.zzce.zzb(Unknown Source:95)
    at com.google.firebase.auth.api.internal.zzbb.zza(Unknown Source:55)
    at com.google.firebase.auth.api.internal.zzcy.zzc(Unknown Source:19)
    at com.google.firebase.auth.api.internal.zzdb.onFailure(Unknown Source:51)
    at com.google.firebase.auth.api.internal.zzci.dispatchTransaction(Unknown Source:101)
    at com.google.android.gms.internal.firebase_auth.zzb.onTransact(Unknown Source:49)
    at android.os.Binder.execTransact(Binder.java:692)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Why you are registering again with this email? Use login with this email instead of trying to register a new account
 
Upvote 0

npsonic

Active Member
Licensed User
Why you are registering again with this email? Use login with this email instead of trying to register a new account
If client is trying to register again with the email that has already been registered, how could I stop it?
Is there any way to check if that email is authenticated?
 
Upvote 0

npsonic

Active Member
Licensed User
Try Catch doesn't work, app will crash even with the whole code in Try Catch
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is there any way to check if that email is authenticated?
You can use Firebase Admin tools to check the userlist. Firebase Admin Tools can only run in Servermode so you´ll need to use B4J for this.

But it is possible to get all registered Accounts with Firebase Admin.
 
Upvote 0

npsonic

Active Member
Licensed User
You can use Firebase Admin tools to check the userlist. Firebase Admin Tools can only run in Servermode so you´ll need to use B4J for this.

But it is possible to get all registered Accounts with Firebase Admin.
You are right there is now API for that, but wouldn't that be very bad practice to get all users everytime when someone is registering there email.
When amount of authenticated users is growing sign up would take longer and longer for each user.
 
Upvote 0

npsonic

Active Member
Licensed User
It seems that you aren't handling exceptions in your code.

Right way to do this would be
B4X:
mAuth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(
                    new OnCompleteListener<AuthResult>()
                    {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task)
                        {
                            if (!task.isSuccessful())
                            {
                                try
                                {
                                    throw task.getException();
                                }
                                // if user enters wrong email.
                                catch (FirebaseAuthWeakPasswordException weakPassword)
                                {
                                    Log.d(TAG, "onComplete: weak_password");

                                    // TODO: take your actions!
                                }
                                // if user enters wrong password.
                                catch (FirebaseAuthInvalidCredentialsException malformedEmail)
                                {
                                    Log.d(TAG, "onComplete: malformed_email");

                                    // TODO: Take your action
                                }
                                catch (FirebaseAuthUserCollisionException existEmail)
                                {
                                    Log.d(TAG, "onComplete: exist_email");

                                    // TODO: Take your action
                                }
                                catch (Exception e)
                                {
                                    Log.d(TAG, "onComplete: " + e.getMessage());
                                }
                            }
                        }
                    }
            );
 
Upvote 0

npsonic

Active Member
Licensed User
I'm not expert on this matter and wouldn't want to create whole library again.

Can't we some how catch the exception, so that it wouldn't crash the app? I have now made some testing with inline java, but can't get anything to work.
App will always crash.

Erel, if you are reading this some expertise is needed here.
 
Upvote 0
Top