Hey guys I am setting up user registration for my app, and the registration itself works fine. Like the email and password is saved in my Firebase authentication section, but I am trying to make it so a Username is stored as well. The code I have seems fine to me, but it won't create a Database in my Firebase with any saved user information like the username.
This is the code I am using to register the users.
firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
//start profile activity here
User user = new User(username, email);
FirebaseDatabase.getInstance().getReference("Users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(RegisterActivity.this, "Registration successful.", Toast.LENGTH_SHORT).show();
startActivity(new Intent(RegisterActivity.this, HomePage.class ));
} else {
Toast.makeText(RegisterActivity.this, "Database not created", Toast.LENGTH_SHORT).show();
}
}
});
} else {
Toast.makeText(RegisterActivity.this, "Registration not successful, please try again.", Toast.LENGTH_SHORT).show();
progressDialog.hide();
}
}
});
When I try to register an account it says "Database not created" so I know that task.isSuccessful() is not true and I am not sure why that is.
Any help?