【问题标题】:Firestore Missing or insufficient permissions after set new rulesFirestore 设置新规则后缺少或权限不足
【发布时间】:2018-12-06 10:06:58
【问题描述】:

我编写了一些与默认规则完美配合的代码。代码是这样的:

function listenerNewMessages(chats) {

        chats.forEach(function(item) {

            db.collection("pm").doc(chats[0]).collection('messaggi')
            .onSnapshot(function(snapshot) {
                snapshot.docChanges().forEach(function(change) {
                    if (change.type === "added" && change.doc.data().idUser != idUser && (String(Date.now()) > change.doc.id  && dateChat < change.doc.id) && idChat != item) {

                        //alert('hai ricevuto un nuovo messaggio in '+ item)
                        $('#contact-'+item).removeClass('flash')

                        setTimeout(function(){
                            $('#contact-'+item).addClass('flash')
                        }, 50);
                    }
                })

            })
        })
    }

但是如果我使用这些规则

service cloud.firestore {
  match /databases/{database}/documents {
    match /pm/{pm} {
      allow read, write: if request.auth.uid == resource.data.partecipanti.partecipante1 || request.auth.uid == resource.data.partecipanti.partecipante2;
    }

  }
}

我明白了

Uncaught Error in onSnapshot: Error: Missing or insufficient permissions.

我做错了什么?

【问题讨论】:

  • 不要删除并重新发布相同的问题。这可能会导致问题被禁止。 stackoverflow.com/help/question-bans
  • 不是同一个问题
  • 改为编辑原始问题(如果没有答案)

标签: javascript firebase google-cloud-firestore


【解决方案1】:

您需要为新写入添加 request.resource 限定符。

allow read, write: if request.auth.uid == request.resource.data.some-property-A || request.auth.uid == resource.data.some-property-A;

allow read, write: if request.auth.uid == request.resource.data.some-property-B || request.auth.uid == resource.data.some-property-B;

【讨论】:

  • 我用正确的属性添加了这两行但结果没有改变,问题不是“新写入”...问题是检测其他用户的新写入
  • 你能添加一张你的数据库的图片吗,pm 展开并且你的auth.currentUser.uid 的最后 4 位数字?
猜你喜欢
  • 2018-08-14
  • 1970-01-01
  • 2019-02-26
  • 1970-01-01
  • 2018-04-25
  • 2020-10-27
  • 2019-05-05
  • 1970-01-01
  • 2020-09-01
相关资源
最近更新 更多