【发布时间】:2018-11-12 23:45:56
【问题描述】:
当我从模拟器运行时,尝试在我的 React Native 应用程序中更新文档工作正常,但当我从实际设备运行时失败并出现错误:“权限缺失或权限不足”。我已经确定我已经登录了。
会引发错误的示例代码:
listing.doc.ref.update({
quantityAvailable: qty
});
//called from an authenticated user who is the author of the listing.
//So the request.auth.uid is equal to the listing.user.id
相关的数据库规则如下:
match /listings/{document=**} {
allow read;
allow create: if isSignedIn();
allow update: if isOwner();
}
...
function existingData() {
return resource.data
}
function incomingData() {
return request.resource.data
}
function currentUser() {
return request.auth
}
function isSignedIn() {
return request.auth != null;
}
function isOwner() {
return request.auth.uid == existingData().user.id;
}
【问题讨论】:
-
请编辑您的问题以包含引发错误的代码。
-
@FrankvanPuffelen,好点,我已经编辑了这个问题。谢谢。
-
您可以像这样
isOwner(userId)向您的isOwner 函数添加参数,这样您的函数isOwner 的条件将是这样的request.auth.uid === userId然后将默认通配符{document=**}替换为{userId}
标签: firebase google-cloud-firestore firebase-security