【发布时间】:2017-07-27 23:54:00
【问题描述】:
我正在开发一个消息 iOS 应用程序,用户可以在其中向多个人发送相同的消息。消息保存在 Firebase 存储中。我只想使已发送消息的用户能够从存储中读取它。我已经在我的 firebase 数据库中实现了这个规则结构。
为了实现这一点以进行存储,我在消息文件 customMetadata 中添加了一个 uid 列表,其中包括编写消息的人的 fromUid 键。我在我的 iOS 应用中执行以下操作:
var metadataValues = [String:String]()
for friendUid in friendsSelected.keys {
metadataValues.updateValue(friendUid, forKey: friendUid) // how do I access these values in my security rules
}
metadataValues.updateValue(senderUid, forKey: "fromUid") // how do I access this in security rules
let messageMetadata = FIRStorageMetadata()
messageMetadata.customMetadata = metadataValues
这是我对 Firebase 存储中消息节点的读写安全规则的尝试,但它不起作用,文档也没有帮助。
match /messages/{messageId} {
allow read: if request.auth.uid == resource.metadata.request.auth.uid; // I want all friend uids to be able to read file
allow write: if request.auth.uid == resource.metadata.fromUid; // only the person who create the message can access it
}
我的尝试不起作用。如何在我的安全规则中使用键“fromUid”和好友 uid“request.auth.uid”访问 customMetadata 变量??
作为旁注,我假设我添加到 customMetadata 的键的数量没有限制?
【问题讨论】:
-
非常感谢您对此的帮助。由于某种原因,我尝试过的一切都没有奏效。
标签: firebase firebase-security firebase-storage