Search code examples
google-cloud-firestorefirebase-authenticationfirebase-security

How to set different rules for different collection


I want my application read only the language collection data from firebase before authentication only and read data from Users collection only when user is authenticated. enter image description here

my rules enter image description here


Solution

  • As far as I can see, you're asking for:

    service cloud.firestore {
      match /databases/{database}/documents {
        match /Language/{document} {
          allow read: if true;
        }
        match /Users/{document} {
          allow read: if request.auth != null;
        }
      }
    }
    

    With the above any user (regardless of their authentication state) can read the Language collection, but only authenticated users can read the Users collection.