无法访问 Firebase 数据库(尽管将读取规则设为 true)



我正在使用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.

即使我使规则"真实"(对任何人开放(,我仍然会遇到同样的错误。在同一应用程序的其他地方,我还有其他有效的读/写功能。

以下是我当前的规则和数据库结构:

{
"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 文档调用规则不是过滤器。

另请参阅有关此主题的许多其他问题中的一些,其中许多问题包含此行为的解决方法。

最新更新