【发布时间】:2019-09-14 10:24:04
【问题描述】:
我在我的 firebase 数据库中添加安全规则时遇到问题。如果经过身份验证的用户等于投票文档上的 uid 属性,我只想允许删除投票。除了我在 match /votes/{voteId} 上创建的删除规则之外,一切正常。
我尝试使用 resource.data.uid 执行此操作,但模拟器抱怨并且我收到错误“运行模拟时出错 - 错误:simulator.rules Null 值错误”
service cloud.firestore {
match /databases/{database}/documents {
match /polls/{pollId} {
allow read;
allow delete: if getUserData().roles.keys().hasAny(['admin']);
allow create: if isSignedIn();
}
match /users/{userId} {
allow read, write: if isOwner(userId);
}
match /votes/{voteId} {
allow read;
allow create: if isSignedIn();
allow delete: if request.auth.uid == resource.data.uid;
}
}
/// Functions ///
function isSignedIn() {
return request.auth != null
}
function isOwner(userId) {
return request.auth.uid == userId
}
}
更新
我也尝试使用 /{document=**} 通配符,它给了我相同的 Null 值错误
match /votes/{document=**} {
allow read;
allow create: if isSignedIn();
allow delete: if request.auth.uid == resource.data.uid;
}
我也尝试使用 get() 函数,但收到错误“未找到函数错误:名称:[get]”
match /votes/{voteId} {
allow read;
allow create: if isSignedIn();
allow delete: if get(/databases/$(database)/documents/votes/$(voteId)).data.uid == request.auth.uid
}
【问题讨论】:
标签: firebase google-cloud-firestore firebase-security