0
votes

Im using Cloud Firestore and im trying to create the security rules. Now I ran into this Problem:
I have a function to get the user data (which is stored in "/user_data")

function getUserData() {
    return get(/databases/$(database)/documents/user_data/$(request.auth.uid)).data;
}

And a dummy function to use this data

function doStuff() {
   return getUserData() == null || getUserData() != null;
}

When I run it (with authenticated user - with user document) It just always returns false

Anyone can help?

1
What is your exact goal? To check if the document at user_data/$(request.auth.uid)exists? Or that a specific field of this document has as specific value? data returns a "map of the document data" and therefore I am not clear on what you want to check with getUserData() == null or getUserData() != null.Renaud Tarnec
I try to check if a list contains a specific value. Since that always fails I wondering if I even got the data. Then I built this dummy function to test and I don't know how to get / use the data map.Stein.
What is the name of this field?Renaud Tarnec
You can get the value of field by doing data.fieldName, see firebase.google.com/docs/firestore/security/…Renaud Tarnec
The name is ownedLists and I want to know if a specific string is in thereStein.

1 Answers

1
votes

The following should do the trick (untested):

function getOwnedLists() {
    return get(/databases/$(database)/documents/user_data/$(request.auth.uid)).data.ownedLists;
}

function checkValueIsIn(valueToCheck) {
   return valueToCheck in getOwnedLists();
}

Based on the following documentation: