小编Moh*_*ran的帖子

如何设置 Firestore 安全规则?resource.data:空值错误

我需要一些帮助来制定 Firestore 工作的安全规则。

这些是我的firestore规则:

service cloud.firestore {
  match /databases/{database}/documents {
     match /orders/{orderID} {
       allow read, update: if  request.auth.uid == resource.data.buyerId  || request.auth.uid == resource.data.sellerId;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我的订单集合:

orders: {
sellerId: 'some-id',
createdAt: timestamp,
buyerId: 'some-id'
}
Run Code Online (Sandbox Code Playgroud)

它应该返回来自订单集合的所有文档,其中买方 ID 或卖方 ID 等于授权用户 (request.auth.uid)。

但上述规则没有按预期工作。

Firestore 集合截图

Firebase 模拟器输出

firebase firebase-security google-cloud-firestore

8
推荐指数
2
解决办法
4034
查看次数