0

仅当用户 uid 是子集合成员中的文档时,我才尝试读取氏族,但我似乎无法让它工作,只是出现更多权限错误。

match /clans/{clanName} {
    allow create;
    allow read: if exists(/databases/$(database)/documents/clans/{clanName}/members/$(request.auth.uid))
            match /members/{uid} {
            allow create,write,delete: if uid == request.auth.uid;
    }
}

调用它的代码使用存储在另一个文档中的引用

this.getProfile
    .data()
    .clan.get());

这相当于

firebase
    .firestore()
    .collection("clans")
    .doc(clanName)
    .get()

在此处输入图像描述

在此处输入图像描述

leaveClan() {
  console.log(this.getUser.displayName + " leaving " + this.getProfile);
  console.log(this.getProfile.data().clan.get().collection("members")
    .doc(this.getUser.uid));
  this.getProfile
    .clan
    .get()
    .collection("members")
    .doc(this.getUser.uid)
    .delete()
    .then(() => {
      firebase
        .firestore()
        .collection("profiles")
        .doc(this.getUser.uid)
        .update({
          clan: null
        });
    });
},

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

0

The way your embedding {clanName} in the get() call is incorrect. Variables are all in $(variablename) format, similar to how you already have $(database) and $(request.auth.uid).

So something like:

if exists(/databases/$(database)/documents/clans/$(clanName)/members/$(request.auth.uid))

Also see:

于 2020-05-16T18:24:40.143 回答