我只希望那些用户读取uid
等于或from
字段message
或邮件的“至”部分设置为all
的邮件。
这是我的数据库:我应该使用哪些Firebase安全规则来阅读邮件?
{
"intents" : {
"intentFields" : "",
"intentName" : "",
"to" : ""
},
"messages" : {
"-KViVgc7ZG051eMXP0-5" : {
"from" : "Ed",
"name" : "Ed",
"photoUrl" : "https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-512.png",
"text" : "Hello, I'm Ed",
"timeStamp" : "1476880306",
"to" : "all",
"type" : "text"
},
"-KWmsuvm0uJIf01eHfyN" : {
"from" : "Capyv3mxQsUUn2W1nPOgcJ0Ex9T2",
"name" : "Aakash Bansal",
"photoUrl" : "https://lh5.googleusercontent.com/-oQyA4HXVycc/AAAAAAAAAAI/AAAAAAAAHKo/Ov0A0p0LjiY/s96-c/photo.jpg",
"text" : "ho",
"timeStamp" : "1479396273",
"to" : "Ed",
"type" : "text"
}
}
}
我会尝试一些规则,太阅读火力地堡文档。但是没有任何规则帮助我实现我的结果。
的,我试过的规则的一个例子是:
{
"rules": {
"intents" : {
".read" : "auth.uid === data.child('to').val()",
".write" : true
},
"messages" : {
"$message": {
".read": "auth.uid !== null",
".write": true
}
}
}
}
而下面一组规则工作得很好,虽然他们没有达到我想要的结果,但他们显示应用程序的所有消息。
{
"rules": {
"intents" : {
".read" : "auth.uid === data.child('to').val()",
".write" : true
},
"messages" : {
".read": "auth.uid !== null",
"$message": {
".write": true
}
}
}
}
只是为了告知,我使用firebaseui在Android应用中读取数据。请告诉我,如果我对“Firebase安全规则”的理解有任何问题。
编辑:即使下面的一组规则不工作:
{
"rules": {
"intents" : {
".read" : "auth.uid === data.child('to').val()",
".write" : true
},
"messages": {
"$message": {
".read" : true,
".write": true
}
}
}
}
,我用它来读取数据了Android的代码是:
mFirebaseAdapter = new MessageAdapter(FriendlyMessage.class,
R.layout.message_my,
RecyclerView.ViewHolder.class,
mFirebaseDatabaseReference.child("/messages"));
怎么样你*阅读*的消息?因为如果你想读取'/ messages',它确实会因这些规则而失败。这是一个常见的混淆来源,我们在文档和[这里的答案中描述为[规则不是过滤器](https://firebase.google.com/docs/database/security/securing-data#rules_are_not_filters) ](http://stackoverflow.com/a/14298525/209103)。 –
你的代码在哪里?你究竟在读什么? (提示:上面的puf的评论几乎肯定是答案,但不能说没有代码) – Kato
是puf,我已经把firebaserecycleradapter放在/ messages,我应该在哪里得到这些消息? –