0

I have this database structure:

database structure

I want the js SDK to be able to write to all the nodes. However, I want to disable .read on the ip node. So when snapchat.val(); is called it returns everything but the ip value.

Reza Mousavi
  • 4,420
  • 5
  • 31
  • 48
Ben
  • 3,160
  • 3
  • 17
  • 34

1 Answers1

1

Instead of having all the details at the same level in the tree, you can create two nodes. One which you call public and the other which you call private.

Here is an example of what you could do:

enter image description here enter image description here

Then, if you want to read the ip later, you could make sure that the user is authorised to be able to read the private_info if that is needed. Or, you could use cloud functions to do something with this data which its access is not limited by rules.

George
  • 25,988
  • 10
  • 79
  • 133
  • This looks good. However how would `public_info` be accessed. In my case `some_random_room` is not a "room" but a "message" with a randomly generated id. When detecting for `"child_added"` the call would be blocked because not all of the data is "readable". – Ben Oct 07 '18 at 12:13
  • You can access public info by doing `rootReference.child(chat/ROOM/public_info)`. I don't understand what you mean by: `When detecting for "child_added" the call would be blocked because not all of the data is "readable"`. Do you mean you want to observe wether the `ip` has had a child added to it? – George Oct 07 '18 at 12:24
  • After converting to all your rules: `firebase.database().ref('chat').on("child_added", function (snapshot) { console.log(snapshot.val()); });` will not return any output because not all of the properties of the "child" node can be read – Ben Oct 07 '18 at 12:37
  • @KALEIDAGRAPH If I was you, I would use a firebase trigger within cloud functions. What would you like to do when you observe the the child being added? – George Oct 07 '18 at 12:43