错误:FIRESTORE (10.7.0) 内部断言失败:意外状态

问题描述 投票:0回答:1

在Flutter中使用集合组查询时出现上述错误。

flutter firebase google-cloud-firestore
1个回答
0
投票

由于缺少集合组查询的权限,我收到此错误,即使我拥有子集合的以下权限

forums

    match /forums/{forumid}/posts/{post} {
      // Only authenticated users can read
      allow read: if request.auth != null;
      // Only the post author can write
      allow write: if request.auth != null && request.auth.uid == resource.data.author;
    }

s 我发现 this 其中指出:

在安全规则中,您必须通过为集合组编写规则来明确允许集合组查询:

  1. 确保
    rules_version = '2';
    是规则集的第一行。集合组查询需要安全规则版本 2 的新递归通配符
    {name=**}
    行为。
  2. 使用
    match /{path=**}/[COLLECTION_ID]/{doc}
    为您的收集组编写规则。

因此像下面这样更新权限是可行的

    match /{path=**}/posts/{post} {
      allow read: if request.auth != null;
    }
    match /forums/{forumid}/posts/{postid} {
      // Only a post's author can write to a post
      allow write: if request.auth != null && request.auth.uid == resource.data.author;

    }
© www.soinside.com 2019 - 2024. All rights reserved.