What Firebase Security rules should I use to read the messages? -
i want users read messages uid
equal either or both to
or from
fields of message
or if 'to' section of message set all
.
this database:
{ "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" } } }
i tries several rules, , read firebase documentation too. none of rules helped me achieve result.
an example of rules tried :
{ "rules": { "intents" : { ".read" : "auth.uid === data.child('to').val()", ".write" : true }, "messages" : { "$message": { ".read": "auth.uid !== null", ".write": true } } } }
whereas following set of rules works fine, although don't achieve desired result display messages in app.
{ "rules": { "intents" : { ".read" : "auth.uid === data.child('to').val()", ".write" : true }, "messages" : { ".read": "auth.uid !== null", "$message": { ".write": true } } } }
inform, i'm using firebaseui in android app read data. please tell me if wrong in understanding of 'firebase security rules'.
edit : following set of rules not working:
{ "rules": { "intents" : { ".read" : "auth.uid === data.child('to').val()", ".write" : true }, "messages": { "$message": { ".read" : true, ".write": true } } } }
android code use read data is:
mfirebaseadapter = new messageadapter(friendlymessage.class, r.layout.message_my, recyclerview.viewholder.class, mfirebasedatabasereference.child("/messages"));
{ "rules": { "messages": { "$message": { ".read": "auth.uid === data.child('to').val() || auth.uid === data.child('from').val() || data.child('to').val() === 'all' ", ".write": true } } } }
Comments
Post a Comment