如何使用规则禁止 Firebase 实时数据库中的用户?

How can I ban a User in Firebase realtime Database using the rules?

我在我的实时数据库中创建了一个禁止用户列表,我想让他们无法登录,我知道我可以使用数据库规则,但我不知道怎么做,有人可以帮忙吗我?

这是我的数据库结构:

/banned-users:
    /UserId1:True
    /UserId2:True

这些是我的数据库规则:

{
    "rules": {
    ".read": true,
    ".write": true
      }

}

您需要reference data in other paths如下:

{
  "rules": {
    "thepath": {
          ".read": "root.child('banned-users').child(auth.uid).val() !== true"
          ".write": "root.child('banned-users').child(auth.uid).val() !== true"
      }
    }
}

请注意,实际上您并没有“让它们无法 log-in”,因为 this is not possible,但是您阻止了它们从您的数据库写入 to/reading。