November 22, 2026 · 9 min read · Thomas Osayi
Firestore "Missing or insufficient permissions": what triggers it and how to fix it
Seeing FirebaseError: Missing or insufficient permissions in Firestore? Causes ranked, how to debug rules in the Rules Playground and emulator, and queries that match.
The console says "FirebaseError: Missing or insufficient permissions." In some SDKs it shows as "PERMISSION_DENIED: Missing or insufficient permissions." with the code permission-denied. The screen is empty, or a save button spins forever, and the same code worked yesterday.
This error is Firestore doing its job. Every read and write from a client SDK is checked against your security rules, and this is what you get when the rules say no. The fix is always one of two things: change the rules so they allow what should be allowed, or change the request so it matches what the rules allow. Here is how to work out which, in the order I check things when someone brings me a Firebase app built with an AI tool.
What triggers "Missing or insufficient permissions" in Firestore?
Any client read or write that your rules do not explicitly allow, because Firestore denies everything by default.
Ranked by how often I find them:
- Test mode rules expired. The database was created with temporary open rules that allow access only until a fixed date.
- The request ran before Firebase Auth finished restoring the user, so request.auth was null when the rule checked it.
- A query does not include the constraint the rule relies on, so Firestore refuses the whole query.
- The rules do not cover the path at all, often a subcollection or a collection renamed by a later prompt.
- A write fails a field check, such as a rule that compares request.resource.data to the user ID.
- The rules in the console are not the rules in your repo, because firestore.rules was edited locally and never deployed, or was deployed to a different Firebase project.
The error message is the same for all of them, so the job is to narrow it down, not to loosen everything until it goes away.
Why did my app work for weeks and then stop?
Almost certainly because the database was started in test mode, and test mode rules include an expiry date.
When you create a Firestore database in the Firebase console, you choose production mode or test mode. Test mode writes rules that allow all reads and writes as long as request.time is earlier than a timestamp a few weeks in the future. On that date every request starts failing at once, for every user, with this exact error.
Open the Firebase console, go to Firestore Database, then the Rules tab, and look for a line comparing request.time to timestamp.date. If it is there and the date has passed, that is your answer.
Do not fix it by moving the date forward or by writing allow read, write: if true. That puts your users' data on the open internet for anyone who finds your project ID, which is in your public JavaScript. Write real rules instead. My checklist in "Firebase best practices before launch: the security rules checklist" walks through the patterns for owner-only data, shared data and admin-only data.
Why do I get permission denied right after sign-in?
Because the Firestore request fired before Firebase Auth had restored the signed-in user, so the rule saw no user.
Firebase Auth restores the session asynchronously when the page loads. If a component runs a query on mount, the first request often goes out with no user attached. Any rule that checks request.auth != null or request.auth.uid then fails.
The fix is in the client:
- Wait for onAuthStateChanged to report a user before subscribing to protected queries.
- In React, keep an auth loading state and render nothing, or a spinner, until it resolves.
- Do not pass a user ID from local storage into a query. Use the uid from the current auth user.
In a Next.js App Router project, the same issue appears when server code tries to use the client SDK without a signed-in user. I covered that setup in "Firebase Authentication in the Next.js App Router: how to do it properly."
Why does my query fail even though the user owns every document?
Because Firestore rules are not filters, and a query is rejected if it could possibly return a document the rules would deny.
The Firebase docs on securely querying data are direct about this: security rules are not filters, queries are all or nothing, and if a query could potentially return documents the client does not have permission to read, the entire request fails. Firestore checks the query's constraints against the rule, not each result.
Say your rule on the orders collection allows read if resource.data.ownerId == request.auth.uid. A query for every document in orders will fail, even if this user happens to own all of them today. The query has to say where ownerId equals the current uid. Then Firestore can prove every result passes the rule, and allows it.
The same logic applies elsewhere in the docs:
- A rule that requires resource.data.published == true needs a query with where published equals true.
- Rules for get apply to single documents, and rules for list apply to queries, so a rule that only defines get blocks all queries.
- A list rule can check request.query.limit, so a query without a limit fails when the rule requires one.
AI builders often write queries first and rules later, so the two drift apart. Line them up field by field.
Why are my subcollections denied when the parent is allowed?
Because a match block applies only to the documents it names, and rules do not cascade down into subcollections.
A rule for match /users/{userId} covers the user documents, not /users/{userId}/orders/{orderId}. That subcollection needs its own nested match block, or a recursive wildcard, which in the rules language is a document variable followed by an equals sign and two asterisks inside the braces. Recursive wildcards are powerful and easy to get wrong, so I prefer explicit nested blocks for each subcollection the app uses.
Two related traps:
- Collection group queries need a rule that matches the collection group across all parents, written with the recursive wildcard at the top level of the database path.
- A later prompt renamed a collection, say from bookings to appointments, and the rules still only mention bookings.
Search your code for every collection and doc path string, list them, and confirm each has a match block.
How do I debug Firestore rules step by step?
Reproduce the failing request in the Rules Playground or the emulator, where you can see which line allowed or denied it.
The Rules Playground
In the Firebase console, open Firestore Database, then Rules, then click Rules Playground. The Firebase docs describe the settings: choose the simulation type (for example get, list, create or update), enter the document path, turn on Authenticated and enter a user ID, and optionally supply document data for writes. Click Run and a banner above the editor says whether access was allowed or denied.
The Local Emulator Suite
For anything beyond a quick check, run the Firestore emulator locally with firebase emulators:start, point your app at it with connectFirestoreEmulator, and reproduce the bug. The Emulator Suite UI lets you inspect the requests your app made against the local database while you reproduce the problem. The Firebase docs recommend the emulator for fuller validation, including automated unit tests of your rules with the rules unit testing library.
Check what is actually deployed
Compare the Rules tab in the console with firestore.rules in your repo, and check the Firebase project ID in your config. Deploy with firebase deploy --only firestore:rules to the correct project.
Why does it work in my server code but not in the browser?
Because the Firebase Admin SDK bypasses security rules, while client SDKs are always checked against them.
If a Cloud Function or a Next.js route handler using firebase-admin can read the data, but the same read from the browser fails, the rules are doing exactly what they should. Do not copy the service account key into the client to "fix" it. Either write a rule that allows the client read, or keep the read on the server and return only what the user should see.
LACEUP, a basketball apparel storefront I built with a Firebase admin dashboard, is a good example of the split this kind of app needs: shoppers browse the catalog, and only admins should be able to change it.

A worked example: a booking app that broke on a Monday
Here is an illustration with a made-up business. A personal trainer's booking app, built in an AI tool on Firebase, works for five weeks and then every page shows "Missing or insufficient permissions."
What I find:
- Test mode rules with a date from last Sunday. I replace them with real rules.
- Clients should read only their own bookings, so the rule checks resource.data.clientId against request.auth.uid. The dashboard query read the whole bookings collection. I add where clientId equals the current uid.
- The trainer needs to see all bookings. I add a role check using a custom claim on the trainer's account rather than a role field users could edit themselves.
- The sessions subcollection under each booking had no rules. I add a nested match.
- The dashboard queried on mount before auth restored. I gate it on onAuthStateChanged.
I test every case in the emulator, then deploy the rules. About half a day of work.
When should I get help with Firestore rules?
Get help when you cannot describe, in one sentence per collection, who should be able to read and write it, because then the problem is the data model, not a single rule.
Rules are only as clean as the structure underneath them. If user data sits in one shared collection with no owner field, or roles are stored in a field that users can edit on their own profile document, no rule can make it safe without changing the data first. That is a bigger job than fixing one denied query, and it is worth doing before launch rather than after a stranger reads your customer list.
Signs it is time for a second pair of eyes:
- You fixed the error by loosening a rule and are not sure what else that opened.
- Some screens work only for the account you built the app with.
- Admin features rely on hiding buttons rather than on rules or custom claims.
- Nobody has ever run the rules against the emulator with a second test user.
If you are deciding whether the app is worth fixing at all, my post "Fix or rebuild your AI-built app? How to decide before you spend more" lays out how I make that call.
The bottom line
"Missing or insufficient permissions" means your Firestore rules said no. Check for expired test mode rules first, then confirm the user is signed in before the request runs, then make sure each query includes the same constraints as its rule, and that every collection and subcollection path has a match block. Use the Rules Playground and the emulator to see exactly which rule denies the request, and never fix it by opening the database to everyone. A single rules bug fits my Quick Fix from $60, and a full rules rewrite with tests usually fits Fix Plus Features from $200.
Questions, answered in one line
What does Missing or insufficient permissions mean in Firestore?
It means the Cloud Firestore security rules evaluated the request and did not allow it, and the SDK reports it with the error code permission-denied.
Why did my Firestore app suddenly stop working with permission errors?
The most common reason is that the database was created in test mode, whose rules allow access only until a fixed date and then deny everything.
Why does my Firestore query fail when every document belongs to the user?
Because rules judge the query by what it could return, so the query must include the same constraint the rule checks, such as a where clause on the owner field.
Why does the Admin SDK work but the client gets permission denied?
The Firebase Admin SDK on a server bypasses security rules entirely, while client SDKs in the browser or app are always checked against them.
How do I test Firestore security rules safely?
Use the Rules Playground in the Firebase console for quick checks and the Firebase Local Emulator Suite to run automated rules tests without touching production data.
Sources
- Securely query data Firebase Docs
- Quickly validate Firebase Security Rules Firebase Docs
- Writing conditions for Cloud Firestore Security Rules Firebase Docs
Related articles
- Supabase auth redirect URL not working? Fix localhost, preview and production redirects
- Environment variables undefined on Vercel? Every cause and fix
- How to fix a CORS error on a Next.js API route
- Firebase auth/unauthorized-domain: how to fix it on Vercel, previews and custom domains
Fix, finish and launch your AI-built app
Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.
See the service