Auth
"FirebaseError: Missing or insufficient permissions" after your Firestore app worked for 30 days
Cataloged November 29, 2026 · Firebase
Symptom
This applies when a Cloud Firestore read or write from a client fails with the message FirebaseError: Missing or insufficient permissions, code permission-denied. If this project does not use Cloud Firestore, this card does not apply. Firebase is the platform tag because the failure is in that project's security rules and client SDK. The pages on this card describe the Firebase CLI's Firestore init template, how queries have to match rules, and when Firebase Auth has a current user. They do not describe a bug in one generator, so the same failure happens on any Cloud Firestore app, including an app an AI coding tool generated. This card does not say Lovable or Bolt write that template. The Firestore JavaScript reference lists the code permission-denied with the description "The caller does not have permission to execute the specified operation." firebase-js-sdk issue 10037, opened June 4, 2026, and closed, prints FirebaseError: Missing or insufficient permissions (code: permission-denied). The report says the error only occurs on page refresh when a session is being restored. This card cites that issue for that text and that context. It does not cite the issue as proof of a bug, and it does not cite the issue as the reason a query ran before Auth was ready. The get-started page for Cloud Firestore Security Rules says every database request from a Cloud Firestore mobile or web client library is evaluated against your security rules before reading or writing any data, and that if the rules deny access to any of the specified document paths, the entire request fails. One cause is the CLI template at templates/init/firestore/firestore.rules. On match /{document=**} it allows read and write while request.time is less than timestamp.date({{IN_30_DAYS}}). The comment in that file says this rule allows anyone with your database reference to view, edit, and delete all data in your database, that it is configured to expire after 30 days because it leaves your app open to attackers, and that at that time all client requests to your database will be denied until you update your rules. src/init/features/firestore/rules.ts replaces {{IN_30_DAYS}} with the year, month, and day from thirtyDaysFromNow(). src/utils.ts defines thirtyDaysFromNow() as Date.now() plus 30 * 24 * 60 * 60 * 1000. The replacement string is getFullYear(), getMonth() + 1, and getDate(), so the month number in the file is 1 through 12. When firebase init firestore runs with a project id and the console already has a ruleset, rules.ts downloads that ruleset instead of leaving the template in place. A second cause is the page "Securely query data". It says security rules are not filters and queries are all or nothing. If a query could potentially return documents the client does not have permission to read, the entire request fails. Its example rule, request.auth != null && request.auth.uid == resource.data.author, rejects db.collection("stories").get() even when the current user is the author of every story. The query it shows succeeding is where("author", "==", user.uid), with user from firebase.auth().currentUser. The same page says a retrieval by document id is evaluated against that document's actual properties. A third cause is a client request that runs before Auth has a signed-in user. The manage-users page says currentUser is null when nobody is signed in, and that currentUser might also be null because the auth object has not finished initializing. It says an onAuthStateChanged observer avoids that intermediate state. The Auth reference says authStateReady() resolves when the initial auth state is settled, and that the current user might then be a valid user or null if the user signed out. The rules-and-auth page says the auth variable is null when the user requesting access is not signed in. The content-owner rules compare request.auth.uid to the owner field, so a request that still has no user is not an owner request. Moving the date forward keeps the template allow, which that file's comment says leaves the app open to attackers. allow read, write: if true is the open-access example on the insecure-rules page, and that page says never use it in production. A rule whose only check is request.auth != null, or request.auth.uid != null, is the any-authenticated-user example, and that page says to confirm you want any logged-in user to have that access. The catalog card "Firebase rules allow every read and write" is the if true case. The catalog card "Any signed-in Firebase user can read the whole database" is the signed-in-only case. The catalog card "A deeper Firebase rule cannot take access away" is Realtime Database cascading rules, which this card does not cover. The longer guide linked from this page is "Firebase security rules allow read, write if true: check your own project".
Root cause
The Security Rules overview says rules are applied as OR statements, not AND statements. If multiple rules match a path and any matched condition grants access, access is granted, and a broad rule cannot be tightened by a more specific rule. Removing the match /{document=**} that contains the timestamp comparison is the repair. Adding an owner rule beside a timestamp rule that still grants does not close that path. While request.time is before the timestamp.date value, the template comment says anyone with the database reference can view, edit, and delete all data. The same comment says that after that time, all client requests are denied until you update the rules. A later date is the same allow. The insecure-rules page prints the content-owner rules that replace a catch-all. Read and delete require request.auth.uid == resource.data.author_uid. Create requires request.auth.uid == request.resource.data.author_uid. Update requires both, so the existing document and the future document stay with that uid. The rules-conditions page says request.resource contains the future state of the document on a write. author_uid is the field name in that insecure-rules example. The rules-query page uses author, and the list query it accepts is where("author", "==", user.uid). The where has to name the field the rule reads. A collection get() with no such where fails even when every stored document would pass a per-document check. A get of one document by id is the case that page evaluates against the actual document, so a failing list beside a successful get of one owned document is the query mismatch. The expired template is the other shape: its comment says all client requests are denied, including a get of one document. The manage-users page is why the first paint can fail an owner rule that is otherwise right. currentUser may still be null because initialization has not finished. Wait for onAuthStateChanged, or for authStateReady(), and run the private query only when that user is non-null. Changing the rule because the first read ran too early reopens data that the owner rule was written to keep private. The get-started page says the server client libraries bypass all Cloud Firestore Security Rules and authenticate through Google Application Default Credentials. The Admin SDK setup page calls the Admin SDK a set of server libraries for privileged environments, and it says end-user access should use the client JavaScript SDK. The insecure-rules closed-access section says the Admin SDK can still read a database whose client rules are allow read, write: if false, and that those rules are for a server-only backend. The rules-conditions page documents a different permission denied. It sets a limit of 10 document access calls for a single-document request or a query, and 20 for multi-document reads, transactions, and batched writes. Exceeding either limit results in a permission denied error. The page says some access calls may be cached, and cached calls do not count. That limit is not one of the three causes above. The page does not say to widen an allow line to get past it. The get-started page also prints allow read, write: if false on match /{document=**}. That is closed access. It is not the 30-day template. This card does not say the console Test mode button writes the timestamp rule. The insecure-rules page says Test mode grants access to all users, and the open example it prints is allow read, write: if true.
Before and after
The before line is the allow in the Firebase CLI's Firestore init template. The template file writes timestamp.date({{IN_30_DAYS}}). rules.ts replaces that placeholder with the year, month, and day from thirtyDaysFromNow(), which utils.ts defines as Date.now() plus 30 * 24 * 60 * 60 * 1000. The template comment says this allow expires after 30 days because it leaves the app open to attackers, and that client requests are then denied until you update the rules. The after lines are the content-owner rules on the insecure-rules page. That page's field name is author_uid. Read and delete check resource.data. Create checks request.resource.data. Update checks both, so the owner does not change. The rules-conditions page says request.resource is the future document. This pair does not move the date forward, does not use allow read, write: if true, and does not stop at request.auth != null. If your documents store a different field name, use that name. The rules-query page uses author, and its matching list query is where("author", "==", user.uid).
Before
allow read, write: if request.time < timestamp.date({{IN_30_DAYS}});After
allow read, delete: if request.auth.uid == resource.data.author_uid;
allow create: if request.auth.uid == request.resource.data.author_uid;
allow update: if request.auth.uid == request.resource.data.author_uid
&& request.auth.uid == resource.data.author_uid;Fix prompt
In this project only. Do not open a Firebase project you do not own. Do not print API keys, tokens, service account JSON, or document contents. Do not set allow read, write: if true. Do not leave request.auth != null, or request.auth.uid != null, as the only condition on private documents. Do not move timestamp.date to a later date. Do not add the Firebase Admin SDK, or a service account key, to client code. Do not send a read or a write to a project this one does not own.
1. This prompt applies if this project uses Cloud Firestore and a client read or write fails with FirebaseError: Missing or insufficient permissions, code permission-denied. The Firestore JavaScript reference describes permission-denied as the caller not having permission to execute the specified operation. firebase-js-sdk issue 10037 prints that FirebaseError text and says the report's case was a page refresh while a session was restored. Do not treat that issue as a bug to code around. If this project does not use Cloud Firestore, say so and stop. The failure is this project's rules or this project's client query. It is not a bug in the tool that generated the app.
2. Open the Firestore rules this project deploys. The insecure-rules page says the Firebase console shows the most recently deployed rules, under Cloud Firestore, then Rules, and that the CLI copy is the rules file named in firebase.json. Show me the match /{document=**} block if there is one. The CLI template allows read, write when request.time < timestamp.date({{IN_30_DAYS}}). rules.ts replaces that placeholder with a year, a month, and a day. If this file has request.time < timestamp.date(year, month, day) on match /{document=**}, the template comment says that date is when all client requests will be denied until the rules are updated, and that the rule exists in that form because it leaves the app open to attackers. Delete that match. Do not edit the numbers to a later date. Also delete allow read, write: if true and allow read, write: if false on match /{document=**} when this app's clients are supposed to read their own documents. if true is the open-access example the insecure-rules page says never to use in production. if false is the closed-access example. Keep a top-of-file rules_version = '2' if it is already there. The get-started page says that line is the version 2 opt-in.
3. Replace the deleted catch-all with per-collection owner rules, using the owner field documents in this project already store. The insecure-rules content-owner example, whose field name is author_uid, is:
allow read, delete: if request.auth.uid == resource.data.author_uid;
allow create: if request.auth.uid == request.resource.data.author_uid;
allow update: if request.auth.uid == request.resource.data.author_uid
&& request.auth.uid == resource.data.author_uid;
The rules-conditions page says request.resource is the future document on a write. The update line checks the existing document and the future document so ownership does not change. Use this project's field name in all three lines. The rules-query page's field name is author, in request.auth.uid == resource.data.author. Do not rename stored fields. Do not copy author_uid into a project whose documents use a different name. The Security Rules overview says rules are OR. Do not leave the timestamp match, or if true, in the file next to these lines.
4. Change list queries so they include the same owner constraint the rule checks. The rules-query page says db.collection("stories").get() fails the author rule even when the user wrote every story, and that this query is the one that fits the rule:
var user = firebase.auth().currentUser;
db.collection("stories").where("author", "==", user.uid).get()
Use this project's collection name and the field from step 3. Keep the SDK style this project already uses. Do not add that where to a get of one document by id. The same page says a single-document retrieval is evaluated against the actual document. If a get of one owned document fails while the rules are the owner rules, go to step 5 before changing the rules again.
5. Do not read currentUser and query in the same first-paint path. The manage-users page says currentUser is null when nobody is signed in, and that it might also be null because Auth has not finished initializing. It shows onAuthStateChanged, from "firebase/auth" and as firebase.auth().onAuthStateChanged, and it says the observer avoids that intermediate state. The Auth reference says authStateReady() resolves when the initial auth state is settled, and the current user may be valid or null. Wait for the callback, or await authStateReady(), and run the private query only when the user is non-null. Take the uid from that user. If the user is null, skip the private query. Do not widen the rules for that null.
6. The rules-conditions page says exceeding the document access-call limits results in a permission denied error. The limit is 10 for a single-document request or a query, and 20 for multi-document reads, transactions, and batched writes. The page says some access calls may be cached, and cached calls do not count. If the rules file is already the owner rules from step 3, the queries already constrain the owner field, and Auth is ready, count those calls before you change an allow line. Do not raise that limit by switching the allow to if true.
7. In the Firebase console Rules Playground for this project, the get-started page says you simulate authenticated and unauthenticated reads against the rules in the editor, not the deployed rules. A signed-out read of a private document should be denied. An authenticated read whose uid equals the owner field should be allowed. The manage-and-deploy page says to open the Rules Playground, modify the settings, and click Run. Do not run the playground in a project this one does not own. For a local run, the insecure-rules page says to use the Cloud Firestore emulator before you deploy. The emulator-suite page says that emulator has Security Rules emulation built in.
8. After the diff is shown and the playground owner read is allowed, deploy this project's Firestore rules with the command on the manage-and-deploy page: firebase deploy --only firestore:rules. That page says this deploys rules for all databases configured in firebase.json. It also prints firebase deploy --only firestore:<databaseId> for one database. Use a database id only when firebase.json already names it. Do not invent one. The same page says a CLI deploy overwrites the rules in the Firebase console with the rules in the project directory. Do not deploy hosting, functions, or any other service. Do not deploy any other project. The get-started page says rules updates can take up to a minute to affect new queries and listeners, and up to 10 minutes to fully propagate to active listeners.
9. Show me the rules diff and the query diff. Do not print keys or document fields. Do not edit unrelated files.Paste this into the coding tool that has your own project open.
2-minute self-check
These steps are for an app you own. Do not run them against someone else's project.
- In a Firebase project you own, open the deployed Firestore rules. The insecure-rules page says the console shows the most recently deployed rules under Cloud Firestore, then Rules, and the CLI file is the one named in firebase.json. If match /{document=**} allows read, write while request.time < timestamp.date(...), note the date in that call. The CLI template comment says that is when all client requests to your database will be denied until you update the rules. The template in firebase-tools contains timestamp.date({{IN_30_DAYS}}), and rules.ts writes the year, month, and day from thirtyDaysFromNow(). Do not open a project you do not own.
- In the Rules Playground for that same project, simulate a signed-out read of a private document and a read as the owner. The get-started page says the playground runs against the rules in the editor, not the deployed rules, and that it can simulate authenticated and unauthenticated reads. The signed-out read should be denied. The owner read, with a uid equal to the document's owner field, should be allowed. A signed-out allow means the open rule is still there. An owner deny means the owner rule is not what the editor is simulating. Do not run this in a project you do not own.
- In your own app, find each list query on a collection whose rule compares request.auth.uid to a document field. The rules-query page says db.collection("stories").get() fails that rule, and where("author", "==", user.uid) is the query that fits a rule on author. Your where field should be the field your rule reads. A get of one document by id is a different check. Do not point a query at a project you do not own.
Common questions
Moving the date forward, or allow read, write: if true, or only request.auth != null, made the error stop. Should I leave that?
No. The Firebase CLI template comment says the timestamp.date rule allows anyone with your database reference to view, edit, and delete all data, and that it expires after 30 days because it leaves your app open to attackers. A later date is that same allow. The insecure-rules page says never to use allow read, write: if true in production, and it says that if a rule includes auth != null you should confirm you want any logged-in user to have access. The catalog card "Firebase rules allow every read and write" is the if true case. The catalog card "Any signed-in Firebase user can read the whole database" is the signed-in-only case. The longer guide on this page, Firebase security rules allow read, write if true, is the check for a project left open.
A list of my own documents fails, and a get of one document by id works. Is that the expired template?
The expired template is the case the CLI comment describes as every client request being denied, which includes a get of one document. A list that fails while a get of one owned document works is the case on "Securely query data": rules are not filters, a query is all or nothing, and db.collection("stories").get() fails a rule of request.auth.uid == resource.data.author even when the user authored every story. The query that page accepts adds where("author", "==", user.uid). Use the field your own rule reads. The page says a retrieval by document id is evaluated against that document.
The error appears on refresh. Should I wait for Auth, or call Firestore through the Admin SDK in the page?
Keep the Admin SDK on the server. If a private query runs while currentUser is still null, that request is not an owner request, so wait for Auth before you change the rules. The manage-users page says currentUser might be null because Auth has not finished initializing, and that onAuthStateChanged avoids that intermediate state. authStateReady() resolves when the initial auth state is settled, and the user may still be null. Run the private query only when that user is non-null. Issue 10037 prints FirebaseError: Missing or insufficient permissions (code: permission-denied) on a page refresh while a session is restored. This card cites that issue for the text and that context. It does not cite the issue as proof of a bug, and it does not cite the issue as proof that waiting removes the error. The Admin SDK setup page says those libraries are for privileged server environments, and that end-user access should use the client JavaScript SDK. The get-started page says the server client libraries bypass Cloud Firestore Security Rules.
Longer guide
- Firebase security rules allow read, write if true: check your own project
What Firebase's open rules and the CLI's 30-day Firestore template allow, what one public-web scan counted, and a check you run only on a project you own.
Sources
- Firebase CLI: Firestore init rules template (30-day timestamp.date allow)
- firebase-tools: Firestore init replaces {{IN_30_DAYS}} (rules.ts)
- firebase-tools: thirtyDaysFromNow (utils.ts)
- Firebase: Securely query data (rules are not filters)
- Firebase: Avoid insecure rules
- Firebase: Security Rules and Firebase Authentication
- Firebase Auth: Manage users (onAuthStateChanged, currentUser)
- Firebase Auth reference: authStateReady()
- Firebase: Get started with Cloud Firestore Security Rules
- firebase-js-sdk issue 10037 (opened June 4, 2026; permission-denied on refresh)
- Firebase JavaScript reference: FirestoreErrorCode permission-denied
- Firebase: Manage and deploy Security Rules (firebase deploy --only firestore:rules)
- Firebase: Writing conditions for Cloud Firestore Security Rules
- Firebase: Security Rules (rules combine with OR)
- Firebase: Add the Admin SDK to your server
- Firebase: Local Emulator Suite (Security Rules emulation)