I'm trying to validate a read in firestore, based on another document.
The data structure consists of 2 collections: "execution" and "test" .
In the test collection there is only 1 document, with the following id: SRJKCxU4HVDBdB3qyfzG, and theese values:
admin true
id: "SRJKCxU4HVDBdB3qyfzG"
test: 1
My security rules look like this:
service cloud.firestore {
match /databases/{database}/documents {
function testFunction(testId) {
// return exists(/databases/$(database)/documents/test/$(testId));
return get(/databases/$(database)/documents/test/$(testId)).data.id == "SRJKCxU4HVDBdB3qyfzG";
}
match /execution/{exeid} {
allow read, write: if testFunction("SRJKCxU4HVDBdB3qyfzG");
}
}
}
If I use return exists(/databases/$(database)/documents/test/$(testId));
everything work's as expected. But no matter what I can't get this line to work return get(/databases/$(database)/documents/test/$(testId)).data.id == "SRJKCxU4HVDBdB3qyfzG"
.
I really hope that I am missing simple and obvious? Any help is very common. I have also created a demo firebase project and stackblitz if necessary.
- Stackblitz https://stackblitz.com/edit/angular-atfasp
- Firebase - send a pm.
Thanks for the help.
Update - temporary solution Because of a firestore security rule bug, the data property is not populated. This will be fixed. The temporary solution for get() to work is the following:
get(path).data.prop || get(path).prop