【发布时间】:2017-03-13 03:09:05
【问题描述】:
我对 Firebase 规则结构感到非常困惑。基本上,我有一个名为“Transactions”的根文件夹,其中包含许多 childByAutoID,它们又包含数据,就像这样:
Transactions {
autoID1 {
transactionID: whatever,
timeCreated: whatever,
"amount": whatever,
"sender": whatever,
"receiver:whatever"
}
}
我现在正在尽最大努力实施最好的安全规则。因此,我尝试做这样的事情:
"Transactions": {
".write": "auth !== null",
"$transactionAutoID": {
"timeCreated": {
".write": "auth !== null && data.child('sender').val() === auth.uid || data.child('receiver').val() === auth.uid",
".read": "auth !== null && data.child('sender').val() === auth.uid || data.child('receiver').val() === auth.uid"
}
}
}
所以基本上,根据我所学到的以及我正在努力解决的问题 - 用户能够编写任何内容,即使在“通配符 ID ($transactionAutoID)”中也是如此。我知道这是因为我已将 Transactions 中的 '.write' 设置为 'auth !== null' - 但如果我没有此设置,用户可能无法读取或写入任何交易数据。 (我将规则默认设置为 false)。
如果我只希望用户能够在 Transactions 中创建新子项,但不写入任何事务密钥(如果他们不是发送方或接收方),我将如何进行?
【问题讨论】:
标签: firebase-realtime-database firebase-security