具有身份验证和不具有身份验证安全规则的 firebase

firebase with auth and without auth security rules

我想创建一个 firebase 规则,让人们无需登录即可使用数据库。但我也想创建一个私有用户节点,只有用户才能通过身份验证访问它,到目前为止我有这样的东西。但这会引发错误

Error saving rules - Line 6: Expected '}'.

{
  "rules": {
    ".read": true,
    ".write": "newData.exists()"
  },
    "test": {
      "$uid": {
        ".read": "auth != null && auth.uid == $uid",
        ".write": "auth != null && auth.uid == $uid"
      }
    }   
}

我不明白为什么上面的不可能

但如果我只做:

  {
  "rules": {
    ".read": true,
    ".write": "newData.exists()"
  }
}

这将起作用,以便任何人都可以使用当前数据,但我想要像 "Test" 这样的私有内容,其中经过身份验证的人只能访问

所以要明确一点,我希望每个人都使用当前的数据库,但我也希望有一些私人部分,比如测试,只有注册用户才能访问

看看https://firebase.google.com/docs/database/security/securing-data

您不能在 "rules" 之后添加元素。它应该是这样的:

{
  "rules": {
   ...
  }
}

不喜欢

{
  "rules": {
    ....   
  },
    ....
}