I want to scan the database while registering a user to check if a certain 'username' is available or taken. I tried it using this code:
mDatabase.child("usernames").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() != null) {
if (dataSnapshot.getValue() == uniqueUserName.getText().toString()) {
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "Username already taken", Snackbar.LENGTH_SHORT);
snackbar.show();
} else {
signingUpMethod();
}
} else {
signingUpMethod();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
But got this log:
W/SyncTree: Listen at /unique-usernames failed: DatabaseError: Permission denied
After doing some research, I find this answer: Firebase Permission denied Error
Current security rules:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
Though it solves the problem, this solution might be handy in testing phase, but what when publishing the app? Please let me know.