Javascript 更改Firebase中的规则后,Firebase权限被拒绝错误
这是我更新的firebase数据库规则。使用静态uid now更新此规则后,错误显示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
"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可能不是一个好的长期情况。