BASIC - Firebase rules

135 views
Skip to first unread message

Lucas Gabriel

unread,
Aug 11, 2023, 10:54:48 AM8/11/23
to Firebase Google Group
{
  "rules": {
    "$caca_palavras": {
        ".read": true,
      "$uid": {
        ".write": true
      }
    }
  }
}

This way above i can write but i can't change if i change $uid rules

{
  "rules": {
    "$caca_palavras": {
        ".read": true,
      "$uid": {
        ".write": "auth !== null && auth.uid === $uid"
      }
    }
  }
}

what could it be? In my head this $uid would be to get the name of the path, but apparently that's not what happens

Frank van Puffelen

unread,
Aug 11, 2023, 10:58:00 AM8/11/23
to Firebase Google Group
If you have an operation that gets rejected by these rules, it's because it doesn't meet the conditions of the rules.

Can you show the minimal code of the operation that is rejected? In that code, prove that it meets the security rules you've set. So when writing, show the UID of the current user (which matches auth.uid) and that it matches the path you're writing to.

Lucas Gabriel

unread,
Aug 12, 2023, 10:06:53 AM8/12/23
to Firebase Google Group
Hi Frank, thanks for taking the time with me;

I've been racking my brains over the rules so far, but doing some testing I've found that the real problem is in the null auth, the variable when equated with the pathname (example: $uid == '6pAY8K2JQ0S7CybyPxhDhPOEZd03') works, but when compared to auth doesn't work.

To demonstrate even better, in the form below I can write:
       
".write": "auth.uid == null"

but that way, even with the user connected to firebase auth, I can't write:
 
".write": "auth.uid != null"

Frank van Puffelen

unread,
Aug 12, 2023, 10:28:30 AM8/12/23
to Firebase Google Group
It sounds like the user is not signed in when you make the call to the database. 

The only way for us to help find why that is, is if you share the minimal code that makes the call to the database and show the relevant values that your rules check in there.

Reply all
Reply to author
Forward
0 new messages