1

I have the following rules setup

{
   "rules":{
      "comments":{
         "$postOwner":{
            ".write":"auth.uid == $postOwner",
            ".read":"auth.uid == $postOwner",
            "$postID":{
               "$postCommenter":{
                  ".write":"auth.uid == $postCommenter"
               }
            }
         }
      }
   }
}

While testing the rules in the simulator they work as expected when i as a postCommenter write to that destination.

When i attempt to write using my app in the following way:

activeDB.ref().child('comments').child(*postOwnerID*)
        .child(*postID*).child(*myAuth.uid*).set('comment here')

The above gives me a permission denied error.

However if i change that final .write condition to true it does work so I know its not a matter of a wrong path. I have manually made sure that my firebase.auth().getUserId() was the same as the destination I was attempting to write was in which case it matched.

So unless I'm not seeing something simple it appears rules containing auth.uid aren't being enforced properly in this case. Not sure what else could be causing this behavior.

Other than to note this is not my main database I'm attempting to write to, its a secondary one in case that could be one of this issues

Update: Here is the error log -

logger.ts:115 [2021-07-25T23:24:32.688Z]  @firebase/database: FIREBASE WARNING: set at /pending/8ni1vZMwexft5xDkjBItdziS1133/-MeSH813lCjnVI6Apw7b/Dpiv7zsM7ZabcF5qqBysRjVsAnM22 failed: permission_denied 
Z @ logger.ts:115
ie.warn @ logger.ts:206
xe @ util.ts:161
(anonymous) @ Repo.ts:526
(anonymous) @ PersistentConnection.ts:641
tn.onDataMessage_ @ PersistentConnection.ts:673
wt.onDataMessage_ @ Connection.ts:321
wt.onPrimaryMessageReceived_ @ Connection.ts:313
(anonymous) @ Connection.ts:210
yt.appendFrame_ @ WebSocketConnection.ts:302
yt.handleIncomingFrame @ WebSocketConnection.ts:354
mySock.onmessage @ WebSocketConnection.ts:224

And more importantly I copied these rules into my main default database and it worked as expected. So certainly looks like a problem with auth on newly created databases

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

0 Answers0