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

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

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

firestore安全规则应如何实现相同?

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

典型的方法是拥有一个包含被阻止用户的集合,每个被阻止用户具有一个文档,并且该文档的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()
    }
  }
}
本文链接:https://www.f2er.com/3113633.html

大家都在问