1

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?

Jafar Mohammed
  • 103
  • 1
  • 12

1 Answers1

2

you can add rules for your nodes separately.

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

    "private_records": {
      ".read": "auth != null"
      ".write": "auth != null"
    },
  }
}
udi
  • 3,672
  • 2
  • 12
  • 33
  • Thanks for the help. What should I do If I have more than one private_records. I mean I want to give permission to global_records and the rest of the records to be authenticated. – Jafar Mohammed Feb 03 '23 at 11:30
  • In your database create two nodes. One for global_records and other one for the private_records. Then add all of your global_records in to global_records node as childs. Do the same for the private_records – udi Feb 03 '23 at 11:33
  • My database is in live I wouldn't want to change so much for that. What I have is like global_records, private_records(has all users), and private_records_deleted(user who wants to delete their account). The global_record is the new field I am adding to this database. – Jafar Mohammed Feb 03 '23 at 11:36
  • It means u have 3 main nodes. right?. So if u apply above rule to the private_records it will be applied to all of its child nodes. – udi Feb 03 '23 at 11:43
  • Yes, So I have to add all 3 nodes so it would work right? It won't work like if global give access, else needs authentication. – Jafar Mohammed Feb 03 '23 at 11:49
  • 1
    yes it will work – udi Feb 03 '23 at 11:51