简体   繁体   中英

Firebase write permission denied

I can't figure out why firebase won't let me do this specific write. I feel like I do it the same in the simulator and it works there. Below are my security rules for this section.

"joinRequests" : {
  "$clanid": {
    "$requesterid" : {
      ".read" : "$requesterid === auth.uid || root.child('clans/' + $clanid + '/members/' + auth.uid + '/admin').val() === true",
      ".validate": "newData.hasChildren(['request'])",
      "request" : {
        ".write" : "true",
        ".validate": "newData.hasChildren(['name', 'message'])",
        "name" : {
        ".validate": "newData.isString()"
        },
        "message" : {
          ".validate": "newData.isString()"
        },
        "$other": {
        ".validate": false
        }
      },
      "approved" : {
        ".write" : "root.child('clans/' + $clanid + '/members/' + auth.uid + '/admin').val() === true || ($requesterid === auth.uid  && !newData.exists())",
        ".validate": "newData.isBoolean()"
      },
      "$other": {
      ".validate": false
      }
    }
  }
},

In the code for my android app I run these two lines:

dataSnapshot.child("request").getRef().removeValue();
dataSnapshot.child("approved").getRef().removeValue();

What I find weird is that it allows me to remove the "approved" value but not the "request" value. The dataSnapshot is a $requesterid. If I run this line in the simulator and it allows the write:

/joinRequests/QV28VJYG/c1cef959-2dd3-4cab-8649-2b81892cffa6/request

The error I get in android studio is this:

W/RepoOperation: setValue at /joinRequests/QV28VJYG/qRlJt4UIAcRVIe9VXoYVBa68tO43/request failed: DatabaseError: Permission denied

It must be something dumb that I'm doing but I can't imagine what it would be. Any help would be great, Thanks.

newData is a snapshot that represent how data will look like after the operation took place.

newData.hasChildren(['request']) tells firebase to make sure that the request node exists after the operation was executed. Therefore, deletion of this node is prohibited.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM