且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

身份验证后读取数据时 Firebase 权限被拒绝

更新时间:2023-02-15 16:11:24

Firebase 的权限模型只允许用户访问您明确授予访问权限的数据.由于在您的安全规则中,您只授予对 /users/$uid 的访问权限,因此用户无法从根 / 读取.Firebase 文档在规则级联"一>.

Firebase's permission model only allows the user access to data that you explicitly give access to. Since in your security rules, you only give access to /users/$uid, the user cannot read from root /. The Firebase documentation covers this under "rules cascade".

您似乎想使用安全规则来过滤数据,而 Firebase 的安全模型无法做到这一点.请参阅规则不是过滤器"部分> 在 Firebase 文档以及之前的这些问题和答案中:

You seem to want to use security rules to filter data, which is not possible with Firebase's security model. See the section "rules are not filters" in the Firebase documentation as well as these previous questions and answers:

最简单的解决方案是允许读取users节点:

The simplest solution is to allow read of the users node:

{
    "rules": {
        "users": {
            ".read": "auth !== null && auth.provider === 'password'"
        }
    }
}

然后在该级别查询:

getData(ref.child("users"));