My database is structured like so...
I want to have different read/write rules for the "users/uid" and "users/uid/locations/$address/latlng" node.
"users": {
"$uid": {
".read": "auth != null && $uid == auth.uid",
".write": "auth != null && $uid == auth.uid",
"locations": {
"$address": {
"latlng": {
".read": true,
".write": false,
}
}
}
}
}
Due to the rules cascade, it seems like this is not possible. The read and write are both passing where I want it to fail. Basically, I want the user to be able to create an address and latlng node under the locations node, but only let certain users create additional nodes under the address node.
Is this possible or will I need to structure my database differently?
Edit:
Here is my code for storing the info to the database
mRootRef.child("users").child(user.getUid()).child("locations").child(currentAddress).child("latlng").setValue(currentLatLng.latitude + "," + currentLatLng.longitude);
Here is my code for retrieving the info from the database
mRootRef.child("users").child(user.getUid()).child("locations").child(selectedItem).child("verified").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//Check if address is verified
if(dataSnapshot.getValue() == null){
ChangeVerifiedMessage(false);
return;
}
if (dataSnapshot.exists()){
ChangeVerifiedMessage(true);
}else{
ChangeVerifiedMessage(false);
}
}

latlngunder theaddressnode, there is no way to create an address without alatlngvalue in your example. Aside from that: anyone can read anylatlngvalue in your database as long as they know the exact path. It might be easier to help, if you show the actual code that you're trying to use against these security rules and the result you get from that. - Frank van Puffelen