Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更改Firebase中的规则后,Firebase权限被拒绝错误_Javascript_Firebase_Firebase Realtime Database_Firebase Security - Fatal编程技术网

Javascript 更改Firebase中的规则后,Firebase权限被拒绝错误

Javascript 更改Firebase中的规则后,Firebase权限被拒绝错误,javascript,firebase,firebase-realtime-database,firebase-security,Javascript,Firebase,Firebase Realtime Database,Firebase Security,这是我更新的firebase数据库规则。使用静态uid now更新此规则后,错误显示Firebase权限被拒绝 "rules": { ".read" : "auth !== null && auth.uid=='xxxxstatic_idxxxx'", ".write" : true } 这是我的配置代码,现在我应该在代码中做什么更改,以便获得从数据库读取的权限 const conf

这是我更新的firebase数据库规则。使用静态uid now更新此规则后,错误显示Firebase权限被拒绝

"rules": {
    ".read" : "auth !== null && auth.uid=='xxxxstatic_idxxxx'",
    ".write" : true
}
这是我的配置代码,现在我应该在代码中做什么更改,以便获得从数据库读取的权限

const config = {
    apiKey: 'xxxxxxxxxx',
    databaseURL: "https://db_name.firebaseio.com/",
    storageBucket: "db_name.appspot.com",
    authDomain: "db_name.firebaseapp.com",
    projectId: "xxxxxxx",
    messagingSenderId: "xxxxxxxx",
    appId: "xxxxx"
};
firebase.initializeApp(config);
根据需要,您应该匹配此模式:

{
  "rules": {
    "users": {
      "$userId": {
        // grants write access to the owner of this user account
        // whose uid must exactly match the key ($userId)
        ".write": "$userId === auth.uid"
      }
    }
  }
}

我知道您只想将权限授予一个特定的用户,那么
$userId
应该替换为
xxxxstatic\u idxxxx

配置代码呢?需要从配置文件传递此uid,然后只有它匹配并获得读取权限。如何从配置文件传递?安全规则本身不做任何事情。请编辑您的问题,以包含生成此错误消息的最小代码。这就是问题,JavaScript中允许我从数据库访问数据的代码是什么。您的标题说,在更改Firebase中的规则后,您遇到了一个
Firebase权限拒绝错误,我认为您没有预料到。请显示意外引发该错误的代码。在规则发生此更改后,我尚未添加任何与firebase连接的相关代码。这就是为什么会出现这种错误。所以我要求提供连接到firebase数据库的代码或JavaScript的任何函数。您的应用程序在哪里或如何验证到firebase?你能包括那个代码吗?另外,
auth.uid=='xxxxstatic\u idxxxx',
的目的是什么?您是否试图将访问权限仅限于经过身份验证的用户或其他对象?例如,硬编码的uid可能不是一个好的长期情况。