Firestore rules on object data type

前端 未结 1 1848
灰色年华
灰色年华 2021-01-13 23:32

The Database have a collection \"Collection\" and each document inside the collection have an object \"members\" which contains the \"uid\" of users who will have access to

相关标签:
1条回答
  • 2021-01-13 23:45

    You need to access the data property to get at any user-created properties, so rules 1, 3, and 5 won't work.

    request.resource generally refers to the data that you're sending down to the database, typically in the case of a write operation, so rule #4 won't work, because request.resource.data will probably be empty in the case of a read.

    Rule #2 does look right, but keep in mind this will only work in the case of fetching a single document. Queries are a little trickier.

    Specifically, if you're running a general "Get every document in my collection" kind of query, Cloud Firestore doesn't have the time to search through every record in your database to ensure that your user has access, so it will reject this query. Instead, you'd need to run a query where Cloud Firestore can "prove" that all documents you'd retrieve will be valid. In your case, for example, you would want to make sure your query is something like "Get every document in my collection where members.(userID) != null". Cloud Firestore rules can then compare your query with its rules and feel satisfied that you'll only get documents you have access to.

    0 讨论(0)
提交回复
热议问题