Reputation: 4841
I have created a working method for create/update/delete of user chat messages. I wonder if there is a way to reduce my logic.
".write": "(!data.exists() && newData.child('uid').val() == auth.uid) || (data.child('uid').val() == auth.uid && newData.child('uid').val() == auth.uid) || (data.child('uid').val() == auth.uid && !newData.exists())"
Multiline for readibility
(!data.exists() && newData.child('uid').val() == auth.uid) ||
(data.child('uid').val() == auth.uid && newData.child('uid').val() == auth.uid) ||
(data.child('uid').val() == auth.uid && !newData.exists())
Upvotes: 0
Views: 491
Reputation: 2688
Take a look into bolt
. https://github.com/firebase/bolt
You can simplify queries, then compile the output.
path /somePath {
path /{uid} {
read() { isUser(uid) }
write() { isUser(uid) }
}
}
function isUser(uid) {
return auth != null && auth.uid == uid;
}
It's really handy - although still in beta, it makes the rules much easier to read and understand.
Upvotes: 1