Ad
Firebase Database Rules For Group-shared Data
My webapp, like 99% of apps, has in db a collection of users. I can access user at /user/ so I setup rule to allow every user to access only its data.
BUT I need every user join a group
/user/34029380432
- name: realtebo
- group_id: 123
- isAdmin: true
/group/123
- a lot of shared data, all members can erad, only isAdmin can write
How can I setup a rule that allow only members of each group to read it and only admin members to write group data ?!
Of course I could swap side, movin member list, as array, under each group and setting, inside each group, one or more admin id.
But I am not able to compose javascript rule.
Ad
Answer
I think what you could do is having a messages and users node within your group objects. You can access to parent object for that data node on your security rules and see if that user is a member of users object node by the use of exists()
/group/123
- messages // a lot of shared data, all members can read, only isAdmin can write
- users // list of user uids that are added to this group
- admins // list of admin uids
"group": {
"$groupId": {
"messages": {
".read": "data.parent().child('users').child(auth.uid).exists()",
".write": "data.parent().child('admins').child(auth.uid).exists()"
}
}
}
Ad
source: stackoverflow.com
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?
Ad