【问题标题】:Firebase Error: Missing or insufficient permissions only when ran from deviceFirebase 错误:仅在从设备运行时缺少权限或权限不足
【发布时间】: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


【解决方案1】:

我可以通过切换到 react-native-firebase 库而不是常规的 node.js Firebase 库来修复它。原来这不是权限问题,我的权限很好,这是 react native 和 node.js firebase 库的网络问题。

【讨论】:

    猜你喜欢
    • 2021-10-31
    • 1970-01-01
    • 2022-01-15
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多