Skip to content
>_VibeUnstuck

Missing or insufficient permissions

Last verified:

The fix

Cloud Firestore rejected the read or write. Security Rules denied it. The client reports FirebaseError: Missing or insufficient permissions, code permission-denied.

  1. 1

    Read the code and the rules you actually deployed

    In the browser console, confirm the code is permission-denied and the message is Missing or insufficient permissions. In the Firebase console, open Firestore, then Rules, and read the rules published to this project. The default deny is allow read, write: if false on /{document=**}. If that is still what is published, the client will never succeed. Do not replace it with allow read, write: if true on a project anyone can open. The insecure-rules guide says that lets anyone who knows the project id read and overwrite the database.

  2. 2

    Match a signed-in user before you blame the query

    A condition request.auth != null is false until Firebase Auth has a user. Sign in, then retry the same call. If the rule compares request.auth.uid to a field, the document has to store that uid. A signed-in user and a rule that still says if false is still a denial.

  3. 3

    Make the query carry the same constraint as the rule

    The rules-query guide's example allows a list only when the query includes the rule's constraint. If the rule is resource.data.author == request.auth.uid, the query needs where("author", "==", user.uid). A collection-wide getDocs is rejected even when every existing row would have passed. Getting one document by its id is evaluated against that document. Do not loosen the rule to if true so an unbounded query can stay.

    const user = auth.currentUser;
    const q = query(
      collection(db, "stories"),
      where("author", "==", user.uid),
    );
    const snapshot = await getDocs(q);
  4. 4

    Use request.resource.data on create

    Split read and write. Reads and deletes see resource.data. Creates see request.resource.data, because there is no stored document yet. An update that must keep the same owner checks both. Publish the rules, then retry the write. The Firebase console data viewer and the Admin SDK bypass Security Rules, so a row you can see there does not prove the client is allowed. Do not put a service account in the app to skip the denial.

Why it happens

The Firestore client throws FirebaseError: Missing or insufficient permissions. with code permission-denied when Security Rules reject the operation. The Firebase insecure-rules guide says a database created in the console starts out denying every user, so a generated app that never deployed rules fails on the first getDocs or addDoc. Rules that allow a signed-in user fail the same way while request.auth is null.

Firestore's rules-query guide says rules are not filters. A query is all or nothing. Rules look at the query's potential result set, not at which documents happen to be in the collection. db.collection("stories").get() fails even when the signed-in user wrote every story, if the rule requires resource.data.author == request.auth.uid and the query has no matching where. A single-document get by id is the exception the same guide calls out: Rules then read that document and evaluate the actual fields.

A write rule has to look at request.resource.data for the incoming document. resource.data is the document already stored, and it is missing on create. Swapping those two denies the write with this same error. This is not auth/unauthorized-domain, and it is not an API-key referrer 403. Those fail before Firestore evaluates the document.

The next error you'll probably hit

Once this is fixed, the usual follow-up is Firebase: Error (auth/unauthorized-domain). Firebase: Error (auth/unauthorized-domain): this host is not in Authorized domains. Add it under Authentication. The Google OAuth list is a separate check.

Prompt to paste back into your AI tool

Paste this above the error.

Firestore returns FirebaseError: Missing or insufficient permissions. (code permission-denied). The call is:
<paste the getDocs / getDoc / addDoc / setDoc>
The published rules are:
<paste the match block>

Do not set allow read, write: if true. Do not put a service account or admin SDK in the client. Do not treat this as auth/unauthorized-domain or an API key 403.

1. Say whether the published rules are still the default deny (if false), require request.auth, or constrain a field.
2. If the user is signed out and the rule requires auth, say so and stop.
3. If the rule constrains a field, add the same constraint to the query (the rules-query guide: rules are not filters). For a single-document get by id, check that document's fields instead.
4. On create, compare request.auth.uid to request.resource.data, not resource.data.
5. Change only that query and that match block.

Common questions

+The Firebase console shows the documents, but the app gets Missing or insufficient permissions. Why?

The console and the Admin SDK bypass Security Rules. The web client is checked against the published rules. A default deny, a signed-out user, or a query that is wider than the rule all produce this error while the console still shows the rows.

+Is this the same as auth/unauthorized-domain or a 403 from the API key?

No. auth/unauthorized-domain means the page's hostname is not on the Auth authorized domains list. An API key referrer or API restriction is an HTTP 403 that names the key, before Firestore rules run. This page is only permission-denied from Firestore.

+Storage says User does not have permission, or the Realtime Database says permission_denied. Same rules?

No. Those products have their own rules. Missing or insufficient permissions with code permission-denied is the Firestore client. Editing the Firestore rules tab does not change Storage or Realtime Database rules.

Related errors