【发布时间】:2018-08-04 07:40:35
【问题描述】:
我正在尝试保护对集合的请求以允许任何单个 get,但仅在匹配特定密钥时才允许 list。
数据库结构是这样的:
projects
project1
name: "Project 1 name"
board_id: "board1"
project2
name: "Project 2 name"
board_id: "board2"
boards
board1
board2
我从 Vue 进行的 Firestore 查询:
// Only return projects matching the requested board_id
db
.collection("projects")
.where("board_id", "==", this.board_id)
我想要的安全规则是这样的:
match /projects/{project} {
allow get: if true // this works
allow list: if resource.data.board_id == [** the board_id in the query **]
// OR
allow list: if [** the board_id in the query **] != null
我想这样做,以便您可以在特定板上列出项目,但不能只列出所有内容。
有没有办法在安全规则中访问请求的.where(),还是我需要将我的projects 集合嵌套在我的boards 集合中并以这种方式保护它?
【问题讨论】:
标签: firebase google-cloud-firestore firebase-security