我正在開發一個消息iOS應用程序,用戶可以將相同的消息發送給多個人。該消息保存在Firebase存儲中。我只想讓已發送郵件的用戶能夠從存儲中讀取郵件。我已經在我的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
這是我爲我的讀取嘗試寫在火力地堡存儲的信息節點的安全規則,但它不工作和文檔是沒有幫助的。
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'和朋友uids的request.auth.uid訪問customMetadata變量?
作爲一個旁註,我認爲沒有限制我添加到customMetadata的密鑰數量?
真的很感謝這方面的幫助。出於某種原因,我試過的一切都沒有奏效。 – Edward