Search code examples
firebasegoogle-cloud-firestorefirebase-authenticationfirebase-security

Firestore Multi-Group Permission Management


Can Firestore security rules manage security permissions across multiple groups? For example, suppose there are individual users Group1 and Group2.

Group1 {
  groupId: string
  groupMembers {
    userId: string 
  }
}

Group2 {
  groupId: string
  groupMembers {
    userId: string
  }
}

Is it possible to manage chat permissions shared by two Groups?

Chat1 {
  editerGroupIds: [groupId, groupId]
}

I thought it would be possible if I could loop the List but Firestore did not support it. Any ideas?


Solution

  • There is no way to loop over things in security rules, as that would never scale. You'll typically want to store the group membership in a way that allows you to implement an in or an exists check in your security rules. So that means you'd keep a collection with UID-keyed documented, or an array with UIDs for your group.