【发布时间】:2020-12-18 10:50:53
【问题描述】:
我有一个可以发送图像的聊天应用程序,我想为 Storage 编写安全规则,以便只有 chats 集合和 UserIds 数组中的内容可以发送图像,但它总是告诉我我是未授权。
service firebase.storage {
match /b/{bucket}/o {
match /Users/{userId}/{allPaths=**} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid == userId;
}
match /Chats/{chatId}/{documents=**} {
allow read, write: if chatRoomPermission(chatId)
}
function chatRoomPermission(chatId) {
return request.auth.uid in get(/databases/$(database)/documents/Chats/$(chatId)).data.userIds;
}
}
}
【问题讨论】:
-
安全规则没有执行它们的代码以及它所依赖的数据就毫无意义。请编辑您的问题以包含重现问题所需的最少代码和您正在检查的数据,并确保在该代码(例如 UID)和聊天 ID 中记录您的规则所依赖的任何值。
-
在我的问题中,我输入了代码 sn-p,它没有显示吗? `
-
您分享了安全规则,但没有分享您应用的代码。 ¯_(ツ)_/¯
-
这里你说从存储安全规则你不能访问云firestore数据库stackoverflow.com/questions/60801027/…
-
啊,我完全忽略了您正尝试从 Storage 规则中的 Firestore 读取数据。这确实是不可能的。
标签: google-cloud-firestore firebase-security