f-miyu / Plugin.CloudFirestore

MIT License
121 stars 44 forks source link

Firestore PERMISSION_DENIED issue #30

Closed Cellus250 closed 4 years ago

Cellus250 commented 4 years ago

Hi all. This is essentially a rehash of issue #8 and a continuation of #11.

I am using this Plugin along with the Plugin.FirebaseAuth. Has anyone had any success with applying Firestore rules to requests generated using this plugin?

I create an anonymous user and attempt to read from the Firestore. My rule works with anonymous authentication when using the simulator. The rule is listed below:

match /{collectionName}/{docId} { allow read: if collectionName != 'CollectionName' && request.auth.token.firebase.sign_in_provider == 'anonymous'; }

However outside the simulator it results in the PERMISSION_DENIED exception. Please let me know if you have any advice.

Cellus250 commented 4 years ago

Yeah I think this was user error. I suppose in my simulator tests of my previous rule set my provided path wasn't deep enough to trigger the rejection. My actual request went deeper.

My rule set was wrong. For anyone else trying to replicate my intent, here is the corrected rule

match /{collectionName}/{docId=**} { allow read: if collectionName != 'CollectionName' && request.auth.token.firebase.sign_in_provider == 'anonymous'; }

This will allow a user that is signed on as an anon user to read all except the specified collection. The part I missed in my first post was the wild card on the docId to allow it to apply to the rules to the collection children (i think).

Thank you for all of your contributions @f-miyu !