I'm trying to check the user's registration if the username is being used by another user. But firebase doesn't have that option unfortunately they do have that option for email but not the username. I know how that is maybe because it is not in the user-auth but only in the database and has to be solved manually. Here this is the code I am using. only nothing is read in the database, but the toast message is displayed even with the names that are not used. and the registration continues even with the names that are used does someone have some kind of solution
private void RegisterNow(final String username, String email, String password){
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
FirebaseDatabase.getInstance().getReference().child("MyUsers").orderByChild("username").equalTo(username).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild(username)){
Toast.makeText(RegisterActivity.this, "Username already in use please!", Toast.LENGTH_SHORT).show();
Intent i = new Intent(RegisterActivity.this, Login_Activity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
finish();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});