Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why cloud firestore rule wont match my path pattern?

So I have a simple database and I want to make a simple rule but for some reason it doesn't want to match my collection

enter image description here

service cloud.firestore {
  match /databases/{database}/documents {

    match /userPrivate/{user=**} {
      allow read, write: if request.auth.uid == user;
    }

  }
}

enter image description here

enter image description here

like image 758
ditoslav Avatar asked Dec 18 '25 05:12

ditoslav


1 Answers

You're not specifying the document to fetch correctly. In the text box that asks you for the location of the document, don't add /databases/(default)/documents. That is added for you automatically. You should specify the path to the document using the collection and document id. For example: /userPrivate/uid where "uid" is the document id. You should probably also turn on authentication in the simulator so that the id is matched.

Also bear in mind that when you use a wildcard match with two stars like /userPrivate/{user=**}, then user variable will contain the entire path of the document, including any subcollections. This means that you rule will not work for documents within subcollections.

like image 156
Doug Stevenson Avatar answered Dec 19 '25 23:12

Doug Stevenson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!