【发布时间】:2019-12-02 11:27:44
【问题描述】:
我正在尝试编写一个 firebase 规则,通过检查另一个节点的数据来检查您是否有权访问一个节点的子节点。我遇到的问题是访问另一个节点的数据,因为它存储在 AutoId 下。如何访问 AutoId 下的数据?
这是我的数据库结构:
{
"products" : {
"Product001" : {
"ownerId" : "User002",
"productName": "Name"
},
"product002" : {
"ownerId" : "User001",
"productName": "Name"
}
},
"shares" : {
"share001" : {
"accepted" : true,
"ownerId" : "User002",
"productId" : "Product001",
"userEmail" : "example@email.com"
},
"share002" : {
"accepted" : true,
"ownerId" : "User001",
"productId" : "Product002",
"userEmail" : "email@exaple.com"
}
},
"users" : {
"User001" : {
"email" : "example@email.com",
"firstName" : "John",
"lastName" : "Smith"
},
"User002" : {
"email" : "email@example.com",
"firstName" : "John",
"lastName" : "Smith"
}
}
}
这是导致我出现问题的规则部分:
"products":{
"$productId":{
".read":"root.child('shares').child($shareId).child('productId').val() === $productId && root.child('shares').child($shareId).child('ownerId').val() === auth.uid",
".write":"root.child('shares').child($shareId).child('productId').val() === $productId && root.child('shares').child($shareId).child('ownerId').val() === auth.uid"
}
}
基本上,用户只有在包含其信息的共享中才被允许访问场所。
感谢您的建议。
【问题讨论】:
标签: firebase firebase-realtime-database firebase-security