John Green
John Green

Reputation: 83

Why is firebase failing to create a new user?

I am trying to make it so that the user can enter in various importation and that firebase can enter this information into the Runtime DB. However, when I press the button that makes the code below happen, it results in the progress bar loading forever. I tried throwing in the log to try to catch some exception, but no exceptions came up. On the firebase console, the user was not created in the authentication and nothing was added to the RunTime DB. I am not sure what is causing this to happen, and I would appreciate any and all help.

Code:

    User user = new User(fullName, email, bio, username,location,realstatus,profilePic);

    FirebaseDatabase db = FirebaseDatabase.getInstance();
    DatabaseReference root = db.getReference().child("Users");

    progressBar.setVisibility(ViewStub.VISIBLE);
    mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if(task.isSuccessful()) {
                Toast.makeText(Register.this, "Create User Succeeded", Toast.LENGTH_SHORT).show();
            }
            else{
                Toast.makeText(Register.this, "Failed to Authenticate :( ", Toast.LENGTH_SHORT).show();
            }
        }
    });
            root.push().setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if(task.isSuccessful()) {
                        progressBar.setVisibility(ViewStub.GONE);
                        Toast.makeText(Register.this, "Data Saved", Toast.LENGTH_SHORT).show();
                    }
                    else{
                        Toast.makeText(Register.this, "Failed to Register User :( ", Toast.LENGTH_SHORT).show();
                        Log.e("Create user", "Failed to create user", task.getException());
                    }
                }
            });

Error:

com.google.firebase.FireBaseException:
An internal error has occured. [ socket failed EPERM:(Operation not permitted) ]

Upvotes: 0

Views: 136

Answers (1)

SABANTO
SABANTO

Reputation: 1506

Add a completion listener to the createUser so you can know why it isn't working.

           mAuth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(LoginActivity.this, task -> {
                    binding.progressBar.setVisibility(View.GONE);
                    if (!task.isSuccessful()) {
                        //get the error here with task.toString();

                    } else {
                        save your database data here
                    }
                });

That will at least help you get to the bottom of why it is failing. Also make sure you have

  1. enabled email auth in firebase console
  2. Have properly set up your app, the SHA-1s, the google-services json and all

Upvotes: 2

Related Questions