如何在Firebase Firestore数据库中标记和报告用户?

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

我有拥有多个用户的应用程序,剩下的主要事情之一就是在firebase中阻止和报告用户。我正在尝试通过谷歌搜索来寻找相同的解决方案,但到目前为止还没有任何成功。

我想知道如何实现这一目标。为此,请指导我,

以及Firestore安全规则应如何实现相同?

ios swift firebase google-cloud-firestore firebase-security-rules
1个回答
4
投票

[典型的方法是拥有一个包含被阻止用户的集合,每个被阻止用户都有一个文档,并且该文档的ID是该用户的UID。

有了适当的结构,您的安全规则可以检查是否存在此类文档,然后阻止用户。

在博客文章7 tips on Firebase security rules and the Admin SDK中有一个很好的例子(技巧7)。那里的规则:

service cloud.firestore {
  match /databases/{database}/documents {
    function isBlackListed() {
      return exists(/databases/$(database)/documents/blacklist/$(request.auth.uid))
    }

    // Collections are closed for reads and writes by default. This match block
    // is included for clarity.
    match /blacklist/{entry} {
      allow read: if false;
      allow write: if false;
    }

    match /posts/{postId} {
      allow write: if !isBlackListed()
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.