1

I'm searching to add a rule in my Firestore database. The rule is to allow write documents if the document equal the request.auth.uid. I don't know how to search the name of my document in the rules.

This is my code where is missing this part :

service cloud.firestore {
  match /databases/{database}/documents {
  match /users/{anyDocument} {
      allow write: if request.auth != null && request.auth.uid == ?????????;
      allow read
    } 
  }
}
Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Jéwôm'
  • 3,753
  • 5
  • 40
  • 73

1 Answers1

5

It's unclear in your question, but I'm assume you want to enforce only writing a document who's id is equal to the users auth id.

match /users/{anyDocument} {

Because of this line, the document id will be set to the variable anyDocument, so this is what you want to check.

allow write: if request.auth != null && request.auth.uid == anyDocument;

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130