I have a login page which when registering a new user authenticates the data if it is validated and then is meant to store them. However, after the data is authenticated it doesn't add to the real time database.
Register java code:
progressBar.setVisibility(View.VISIBLE);
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
User user = new User(fullname, 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()){
progressBar.setVisibility(View.GONE);
Toast.makeText(RegisterActivity.this, "User has registered successfully", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(RegisterActivity.this, "Failed to register", Toast.LENGTH_LONG).show();
}
progressBar.setVisibility(View.GONE);
}
});
}
else{
Toast.makeText(RegisterActivity.this, "Failed to register22", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
});
}
}
Dependencies:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.firebase:firebase-auth:21.0.4'
implementation 'com.google.firebase:firebase-database:20.0.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
I have set the rules of the database as below:
{
"rules": {
".read": true, // 2022-6-14
".write": true, // 2022-6-14
}
}
Finally my database also only shows this:
https://hobby-tracker-a914f-default-rtdb.europe-west1.firebasedatabase.app/
:
null
Does anyone have any clue why this is happening?