1

How can I grant access to Firebase locations to groups of users?
I found a good solution for only a group of users: Access to Firebase locations for a group of users It has the property group: "group name" but in my case, it should have a property groups: [ 'group1', 'group2', ] or groups: 'group1, group2, ...'. groups can be a dictionary object {'group1': true, 'group2': true}.

Here is the JSON structure.

"Groups": {
  "group1": { "user1": true, "user2": true, ...},
  "group2": { "user3": true,  "user4": true, ... },
  "group3": ...,
  ...
}
"Products": {
   "product1": {
       ...
       "groups": ["group1", "group2"],  "group1 group2" or 
                 {"group1": true, "group2": true} 
   }
} 

So the users user1, user2, user3, user4, members of group1, group2 can access the product product1.

Colin Wang
  • 6,778
  • 5
  • 26
  • 42
  • Possible duplicate of [Granting access to Firebase locations to a group of users](https://stackoverflow.com/questions/14491496/granting-access-to-firebase-locations-to-a-group-of-users) – Pipiks Jul 27 '17 at 12:53
  • 1
    It is not the duplicate, there should be a another solution for multi-group access. – Colin Wang Jul 27 '17 at 13:08
  • 1
    The linked answer shows how to handle groups. There is no better way. The difference with your sample is that you use an array, which is an anti-pattern when it comes to Firebase. One of the many reasons Firebase recommends against using arrays is that it makes the security rules impossible to write. For more see [this blog post](https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html) and [my answer here](http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value). – Frank van Puffelen Jul 27 '17 at 13:22
  • 1
    If you're having trouble making the solution in Michael's answer work for your case, edit your question to include the minimal JSON and security rules (as text, no screenshots) and we'll have a look. – Frank van Puffelen Jul 27 '17 at 13:23
  • 1
    @FrankvanPuffelen I am really looking for a solution for multiple groups for a location, not a single group. – Colin Wang Jul 27 '17 at 14:53
  • We really need to see your Firebase structure (TEXT please, no images or links) to generate an answer. The question is a tad vague with out it. – Jay Jul 27 '17 at 15:08
  • Thanks for that JSON. I'd recommend doing what everyone by now has recommended and only consider `"group1": true`. Now what rules did you already write? What is the problem with them? – Frank van Puffelen Jul 27 '17 at 15:42
  • 1
    The problem is I am not sure how to write rules for it looping through the group object in rules. – Colin Wang Jul 27 '17 at 16:02

0 Answers0