Firestore 安全规则获取功能错误

Nán*_*űcs 3 firebase firebase-security firebase-authentication google-cloud-firestore

当用户注册时,应用程序使用为 Firebase 身份验证生成的相同uid将用户保存在 Firestore 中。现在,我试图写一个地方分开收集(没有用户采集)安全规则的读取写入操作被允许仅当请求者有请求者isAdmin字段设置为true。正如您在图像上看到的,即使get()函数中的路径是正确的,我也收到了一个不存在的错误。什么可能导致此错误?

我尝试了路径的许多变体、更改集合、小写所有内容等。我在 Google 中找不到任何关于此的内容,官方文档显示的用法与我使用它的方式相同。

安全规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /user/{user} {
      allow read,write: if true
    }
    match /akarmi/{akarmiId} {
      allow read, write:
      if get(/databases/$(database)/documents/user/$(request.auth.uid)).data.isAdmin == true
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我希望此代码能够运行并允许或禁止访问,并且不会抛出不存在的错误。

Nán*_*űcs 5

我通过以下配置解决了我的问题: 在此处输入图片说明

您必须设置一个真实的 Firebase UID 才能使用模拟器,实际的 UID 解决了问题,错误消息非常具有误导性。