Firebase database rules for particular field

I have a Firebase database JSON in a format

global_records
    field1:
private_records
    field_A:
    field_B

And I have rules set as

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

When I call observeSingleEventOfType to get globar_records I get the error permission_denied. This works when Sign In.

How do I only allow access to global_records to all the users and need to authenticate to access private_records?

>Solution :

you can add rules for your nodes separately.

{
  "rules": {
    "global_records": {
      ".read": true
      ".write": true
    },

    "private_records": {
      ".read": "auth != null"
      ".write": "auth != null"
    },
  }
}

Leave a Reply