Javascript 无法访问firebase数据库(尽管使读取规则为true)
我正在使用React Native和Firebase构建一个应用程序 在另一个应用程序(从firebase中提取)中工作的代码这次无法工作。因此,我对其进行了修改,使其更简单—一次数据调用,并得到以下错误:Javascript 无法访问firebase数据库(尽管使读取规则为true),javascript,firebase,firebase-realtime-database,firebase-authentication,firebase-security,Javascript,Firebase,Firebase Realtime Database,Firebase Authentication,Firebase Security,我正在使用React Native和Firebase构建一个应用程序 在另一个应用程序(从firebase中提取)中工作的代码这次无法工作。因此,我对其进行了修改,使其更简单—一次数据调用,并得到以下错误: Possible Unhandled Promise Rejection (id: 0): Error: permission_denied at /userList: Client doesn't have permission to access the desired data. 即
Possible Unhandled Promise Rejection (id: 0):
Error: permission_denied at /userList: Client doesn't have permission to access the desired data.
即使我让规则“真实”(对任何人开放),我仍然会得到同样的错误。在同一个应用程序的其他地方,我还有其他可以工作的读/写功能
以下是我当前的规则和数据库结构:
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
},
"public": {
"$uid": {
".read": "auth != null",
".write": "auth != null"
}
},
"feedback": {
"$uid": {
".read": "auth != null",
".write": "auth != null"
}
},
"userList": {
"$uid": {
".read": "auth != null",
".write": "auth != null"
}
}
}
}
下面是我的动作创建者,他发出了呼叫:
import firebase from 'firebase';
export const NAMES_FETCH = 'names_fetch'
export const namesFetch = () => {
return (dispatch) => {
firebase.database().ref(`/userList`).once('value').then(function(snapshot) {
var names = snapshot.val();
console.log('FIREBASE PRINT', names)
});
};
};
我什么都试过了,现在束手无策。谢谢大家! 连接侦听器时,Firebase会检查读取权限。如果您对该位置具有读取权限,则允许进行读取或查询。如果您对该位置没有读取权限,则将拒绝读取或查询 在您的情况下,读取将被拒绝,因为没有人具有对
/userList
的读取权限
所以:要查询某个位置,您必须具有该位置的读取权限。一旦您拥有某个位置的读取权限,您还可以读取该位置下的所有数据。这意味着查询不能用于筛选Firebase文档调用的您无权访问的数据
还可以看到许多其他代码,其中许多包含此行为的解决方法。忘了提到,如果我将ref改为“users”而不是“userList”,同样的代码也可以工作。谢谢你的快速回答!只是一个后续问题:为什么没有人拥有/userList的阅读权限?我想这是userLi下我的规则所允许的st.最简单的解决办法是给予所有人阅读许可,但从你的回答来看,我猜这违反了规则,不是过滤准则???谢谢我看到了我的错误。谢谢你的回答!