How to allow user with specific User UID under Authentication section to write to Firestore and rest users to read data for a specific document?

Viewed 631

I am trying to allow just one user with specific UID under authentication section to write to a document and rest to read from it.

I have tried nothing yet as I am not able to understand the concept behind it.

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }
  }
}

I expect output to be complete Firestore rules I can use directly also an explanation of concept will be much appreciated.

1 Answers
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read : if request.auth.uid != null;
      allow write,delete : if request.aurh.uid = userId //you'll have to fetch userId from document. You can store userId in a field like 'createdBy'
    }
  }
}
Related