I want to let users find a record by value, but I don't want them to be able to list all records.
For example I want to create a wiki, and I want some pages to only be accessible by direct urls.
I know I can give read access on the record level, and a user wouldn't be able to read all keys, but then I'm limited to only characters allowed for a key, while I might want to use /
and other characters.
So I would store a thing's path in it's path
property and then look for the thing by path
;
// database structure
things
-KNi4OQXGXsHKYHVuTln
path: "should/not/be/listed/anywhere"
I want to let the user to find the thing only if they know the path.
The problem is I can only find the thing by searching /things
with orderByChild
and equalTo
:
// request with javascript
firebase.database()
.ref('/things').orderByChild('path')
.equalTo("should/not/be/listed/anywhere")
.once('value', s=>{ });
Which means I would have to give read access to /things
:
// database security rules
{
"rules": {
"things": {
".read": true,
".indexOn": ["path"],
"$thingId": {
".validate": "newData.hasChildren(['path']) && newData.child('path').isString()"
}
}
}
}
and that effectively lets anyone see all the things that I have. Is there a way to avoid that?
And if not, does that mean Firebase forces me to make all my things public as soon as I want to find by a property value?