我试图只允许读/写一个用户的 UID,但是脚本一直说缺少权限请帮助。
非常感谢`
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, update, delete: if request.auth.uid == userId;
allow create: if request.auth.uid == userId;
}
}
}
db.collection('users').doc(userId).collection('details').add(...
最佳答案
您编写的规则仅匹配紧邻名为“users”的集合中的文档。但是,您正在尝试访问“用户”下文档的子集合 中的文档。
documentation非常具体地解决了这种情况,因此请务必阅读并理解分层数据如何适用于安全规则。
如果您想将每个用户的规则应用到一个集合中的所有文档,以及所有所有嵌套子集合中的文档文件,你可以简单地说:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read: if request.auth.uid == userId;
match /{document=**} {
allow read: if request.auth.uid == userId;
}
}
}
}
请注意,必须像这样嵌套匹配才能使用外部匹配中的 userId
通配符。
关于javascript - 尝试仅添加到用户时不断获得缺少的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51811941/