Reputation: 386
Most of my Firestore rules are working. Finding If A User is Signed and has a document under Clearance. The only thing is, I want to find out what that clearance is. To do so I the function
function UserClearance() {
return Number(
get(/databases/$(database)/documents/Clearance/$(request.auth.uid)).a ||
get(/databases/$(database)/documents/Clearance/$(request.auth.uid)).data.a
);
}
That I then compare to a number like so
allow write: if UserClearance() > 1;
Though I have has no success with this function and was wondering how I get it to work.
Upvotes: 3
Views: 1283
Reputation: 1
I had the same problem and I had an array in the database with {data: {a: 1}} instead of {a: 1}. So when you call get().data, don't use it in the database the keyword data. Just a.
Upvotes: 0
Reputation: 435
Try this. It works for me:
// helper functions
function clearance(database) {
return get(/databases/$(database)/documents/Clearance/$(request.auth.uid)).data.a > 1
}
// security rules
service cloud.firestore {
match /databases/{database}/documents {
match /Clearance {
allow read: if clearance(database);
}
}
}
Make sure that you use the variable database
in the right scope.
Resource: Firebase guides: access other documents
Upvotes: 4