I am trying to push data to my database and I want to check if the pushed data's owner id is the same as the uid of the person pushing it. I get permission denied . I don't know how to write security rules for pushing data, and I can't find anything about it. The data structure looks like this:
Shops{
"Shop1PushId" : {
"ShopCredentials" : {
"Owner" : "ownerUID"
}
}
"Shop2PushId" : {
...
}
This is the object I am pushing.
{
"ShopCredentials" : {
"Owner" : "owner_id",
"Another" : "another thing"
}
}
This is my firebase rule:
"Shops" : {
".read" : true,
".write" : "newData.child('ShopCredentials').child('Owner').val() === auth.uid"
}
Code in android studio:
DatabaseReference shopsRef = database.getReference("Shops");
shopsRef.push().child("ShopCredentials").child("Owner").setValue(shopData.getShopOwner());