0
votes

Here are my rules

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /Users/{id}{
        allow read : if (request.auth.uid == resource.data.uid);
      allow write : if false;
    }
    
   
    match /Class/{id}{
        allow read : if (request.auth.uid == resource.data.instructor.uid || (request.auth.uid == resource.data.admin.uid));
     
      allow write : if false;
    }
   
    match /Class/{id}/Topics/{doc} {
             allow read:
       if request.auth.uid == resource.data.topicOwnerUID || request.auth.uid == resource.data.adminUID
        allow write: if false;
        }
    
  }
}

Everything is fine except trying to pull all the topics from Class/docs/Topics/docs. I use getDocuments and try to get all documents using limit(50), I only have 1 topic now, but I also tried making limit to 1 and still don't work.. In each of the Topics docs, there is an adminUID and a topicOwnerUID field. When the owner tries to pull all documents I am getting an error: "Error: Missing or insufficient permissions.". I checked and all the required fields are there and this should allow.

Edit: seems like if i remove .limit and just get a single doc with a specific docID it works. But this isn't what I want :/. Maybe I will have to make the subcollection into its own collection.

Edit2: doesn't work even if it is not a subcollection. completely lost rn. Looks like the only way is to get each doc individually but this ruins lazyLoading. Firebase is lagging behind. will be switching to another db.

1

1 Answers

1
votes

Security rules do not mean anything without the matching queries - remember that Security Rules ARE NOT FILTERS - they will NOT "just give you the records that are allowed" - you MUST use queries to match your rules. If your query could return a document that isn't allowed by the rules, then the ENTIRE query is disallowed.

I can tell you from EXTENSIVE use that Firebase/Firestore do not lag behind in any way, and I use complex queries continuously.