Reads or writes to Firestore fail with 'Missing or insufficient permissions', even though the user appears to be authenticated, usually due to security rules not matching the request.

Use the Firestore Rules Playground and the Local Emulator Suite to test rules against the actual request shape before deploying.

Step-by-Step Guide

1

Open the Firestore Rules tab and simulate the exact failing request in the Rules Playground

2

Confirm request.auth != null for any rule requiring authentication

3

Match document ownership explicitly: resource.data.userId == request.auth.uid

4

Remember nested subcollections need their own match blocks - rules aren't inherited automatically

5

Use the Firebase Local Emulator Suite to test rules locally before deploying

6

Log the current user's UID client-side to confirm it matches the expected owner field

7

Avoid 'allow read, write: if true' in production rules

8

Deploy updated rules with: firebase deploy --only firestore:rules

Found an issue with this solution?

Related Topics

firestore emulator setupfirebase auth custom claimsfirestore composite index required