【问题标题】:The caller does not have permission to execute the specified operation调用者无权执行指定操作
【发布时间】:2021-05-20 05:43:53
【问题描述】:

我正在尝试构建一个包含聊天的应用,但出现错误消息:

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: [cloud_firestore/permission-denied] 调用者没有执行指定操作的权限。

我的 Firebase 规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
  
match /users/{uid}{
allow write: if request.auth != null && request.auth.uid == uid;
}

match /users/{uid}{
allow read: if request.auth != null;
}

match /chat/{document=**}{
    allow read: if request.auth != null;
    }
  }
}

enter image description here

如上图所示,当我写消息并发送时,它并没有出现在屏幕中,错误消息是在终端中写入的

【问题讨论】:

    标签: flutter google-cloud-firestore firebase-security


    【解决方案1】:
    rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, 
          write: if true;
         }
      }
    }
    

    这可以在不需要认证访问时使用。

    【讨论】:

    • 为什么要使用它而不是其他解决方案?不无条件地允许写访问不是更好吗?
    • 这个可以在不需要认证访问的时候使用。
    • 这是edit 回答的好信息。
    【解决方案2】:

    您可以按照以下方式制定规则。它也很安全

    rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, write: if request.auth != null;
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-09
      • 2021-03-03
      • 2022-08-06
      • 2021-07-25
      • 2021-10-08
      • 2021-12-26
      • 2021-10-01
      • 2015-03-27
      • 1970-01-01
      相关资源
      最近更新 更多