Firestore security rules : searching for a user's id in array in a document

前端 未结 2 2046
故里飘歌
故里飘歌 2020-12-05 07:03

First, sorry for my terrible English, it is not my native language...

I am building a simple app in Firebase, using the Firestore database. In my app, users are memb

2条回答
  •  星月不相逢
    2020-12-05 07:26

    I made it happen with this code

    Allow some user to read/write some document of a collection if this same user is present into an array of another collection

    service cloud.firestore {
      match /databases/{database}/documents {
        match /repositories/{accountId} {
          allow read, write: if request.auth.uid in get(/databases/$(database)/documents/accounts/$(accountId)).data.users
        }
      }
    }
    

提交回复
热议问题