Now I have these rules
{
"rules": {
"users":{
"$uid":{
".write": "$uid == auth.uid",
".read": "auth != null && auth.uid == $uid"
}
}
}
}
When authorizing, I write data to the database along this path
Further in the application, I want to display all user emails, but nothing is displayed.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read);
listView = findViewById(R.id.textView);
listData = new ArrayList<>();
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, listData);
listView.setAdapter(adapter);
mDatabase = FirebaseDatabase.getInstance().getReference();
mAuth = FirebaseAuth.getInstance();
getDatafromDB();
}
private void getDatafromDB(){
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (listData.size() > 0) listData.clear();
for (DataSnapshot ds: dataSnapshot.child("users").getChildren()){
User user = ds.getValue(User.class);
assert user != null;
listData.add(user.email);
}
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
};
mDatabase.addValueEventListener(valueEventListener);
}
}
If I write the initial rules,
{
"rules": {
".write": "false",
".read": "true"
}
}
then everything is displayed. Based on this, I conclude that I am setting the rules incorrectly. How to do it right?