How to filter out/hide secret attributes in Firebase?
For example, if I have a data store:
"people": {
"ivan": {
"age": 23,
"location": "Australia"
"password": "123",
"underGroundLover": "JLo"
}
}
I want to hide password
and underGroundLover
from general audiences while they are able to fetch node ivan
.
From my understanding, Firebase's authorisation/security rule/node fetching logic is simply "all or nothing", so that if I want to filter out some secret properties from a node, I will have to either:
Use my own server/lambda to filter out secrets before passing data to users. Which defeats the purpose of BAAS.
Use a weird denormalised data structure to separate public accessible and permission-required attributes. Which will introduce a large amount of n+1 queries.
Option 2's denormalised data structure with rules will be something like this (I know data and rules don't live together):
{
"rules": {
"public": {
"people": {
".read": true,
"ivan": {
"age": 23,
"location": "Australia"
"passwordRef": "/non-public/people/ivan/password",
"underGroundLoverRef": "/non-public/people/ivan/underGroundLover"
}
}
},
"nonPublic": {
"people": {
".read": false,
"ivan": {
".read": false,
"password": {
".read": if(user === "ivan" || user.group = "admin" || user.group === "ivan's parent")
},
"underGroundLover": {
".read": if(user !== "ivan's wife")
}
}
}
}
}
}
Is there any other more efficient way that I can implement filter? If Firebase can answer me, I'd also want to know why security rule or data fetching have to be all-or-nothing? Wouldn't it be nice if Firebase can filter/hide data base on rules?