November 17, 2026 · Updated November 27, 2026 · 12 min read · Thomas Osayi
Firebase best practices: the 2026 pre-launch checklist (rules, costs, App Check)
Firebase best practices in one checklist: locked-down Firestore and Storage rules, server-only admin actions, App Check, cost-safe queries, indexes and separate projects.
Firebase is safe when its rules are right. The config in your frontend is public, so the rules are the only thing standing between a stranger and your data.
That sentence is the whole security model, and it is the part AI app builders most often leave unfinished. The app works, sign-in works, data saves and loads, and the rules file still says anyone may read and write everything. This checklist is the pass I do on every Firebase app before it goes live, written so you can do it yourself.
What are the most important Firebase best practices?
The short version: lock down your rules, keep privileged work on the server, protect your bill, and separate your environments.
Here is the whole checklist on one screen. Every item has its own section below.
- Security rules: no open or test-mode rules, every document tied to its owner, users cannot write their own role, plan or balance
- Storage rules: private files under a user ID path, with size and file type limits
- Server-only work: role changes, payments, credits and cross-user writes run with the Admin SDK behind a verified ID token
- Abuse protection: App Check enforced, API keys restricted, unused sign-in providers disabled
- Cost control: cursor pagination instead of offsets, listeners scoped to small queries, budget alerts set
- Data design: automatic document IDs, index exemptions for fields you never query, no single document written by every user
- Operations: separate development and production projects, more than one owner, rules tested before every deploy
If you only have an hour, do the first three. They are where real data leaks come from.
Why are security rules the only thing protecting my Firebase data?
Because the browser talks to Firestore and Storage directly, with no server of yours in between, and the keys it uses are visible to everyone.
In a traditional app, the browser calls your server and your server decides what to return. With Firebase's client SDK, the browser sends its query straight to Google's servers. The apiKey, projectId and the rest of the config object ship inside your JavaScript, and anyone can copy them from the page source. That is by design. The config only identifies the project.
What decides whether a request succeeds is the rules: a small file that Firebase evaluates on its own servers for every read and write. Hiding a button in your interface protects nothing. Someone can open the browser console, paste your config into a few lines of code, and query any collection by name. If the rules allow it, they get the data.
So the question for every collection is not "does my app ever show this?" It is "what happens when a stranger asks for it directly?"
How do I find open rules in my project?
Open firestore.rules and storage.rules, or the Rules tab in the Firebase console, and search for three patterns.
The fully open rule
allow read, write: if true gives the whole internet access. It sometimes sits under a catch-all path, match /{document=**}, which applies to every document in the database.
Test mode
When you create a database in test mode, Firebase writes a rule that allows everything until a date about 30 days out: allow read, write: if request.time < timestamp.date(...). Two bad outcomes follow. Before the date, your data is public. After the date, every request is denied and the live app suddenly stops working. Firebase emails warnings about both. Many founders push the date forward to make the app work again, which reopens the hole.
Signed-in is not the same as allowed
allow read, write: if request.auth != null looks like security. It means any signed-in user can read and change every document, including other people's. Since anyone can create an account in your app, it is one sign-up away from open.
One more behavior to know: rules are additive. If any matching rule allows a request, it is allowed. A careful rule on /users/{userId} is undone by a leftover catch-all that allows everything, so delete the broad rules and do not just add narrow ones beside them.
How do I restrict documents to the user who owns them?
Compare request.auth.uid with the owner on every read and write, and check it on create as well as update.
Two common layouts
If the document ID is the user ID, as in /users/{userId}, the rule is: allow read, write: if request.auth != null && request.auth.uid == userId.
If documents carry an owner field, as in /orders/{orderId} with a userId field, compare against the stored data: allow read: if request.auth.uid == resource.data.userId.
Create needs its own check
On create there is no existing document, so check the incoming data: request.resource.data.userId == request.auth.uid. Without it, a user can create an order that belongs to someone else. On update, also require that the owner field does not change.
Rules are not filters
Firestore will not quietly return only the documents a user may see. If a query could include documents the rules forbid, the whole query fails with "Missing or insufficient permissions". A query for all orders fails. A query for orders where userId equals the current user's ID succeeds. If your app starts throwing permission errors after you tighten the rules, the queries need a matching where clause.
Subcollections
A rule on /users/{userId} does not cover /users/{userId}/notes. Write a match for each subcollection.
How do I stop users editing their own role, plan or balance?
Split write into create, update and delete, and list exactly which fields each one may touch.
Ownership is half of it. If a user owns their profile document and the rule says the owner may write, the owner can write anything, including role: 'admin' or plan: 'pro' or credits: 99999. They do not need your interface to do it.
The tools inside rules:
- On update, allow only named fields to change: request.resource.data.diff(resource.data).affectedKeys().hasOnly(['displayName', 'photoURL'])
- On create, allow only known keys: request.resource.data.keys().hasOnly([...])
- Check types and sizes: request.resource.data.title is string, and request.resource.data.title.size() <= 200
- Check that numbers fall in a sensible range, and that references point at documents the user may use
The cleaner design is to keep sensitive fields out of user-writable documents entirely. Put role, plan, subscription status and balances in a document, or in custom claims, that only the server writes. Then the user's profile rule can be simple, because nothing in that document matters to security.
Also decide deliberately who may delete. Many apps should not let a user delete an order or an invoice at all.
Which actions belong on the server instead of the browser?
Role changes, payments, refunds, credits and anything that touches more than one user's data should run on the server with the Admin SDK.
The Admin SDK bypasses security rules. That is safe on code you control, such as a Next.js route handler, a server action or a Cloud Function, and unsafe anywhere else. The pattern is:
- The browser sends the user's ID token with the request
- The server verifies the token with the Admin SDK and reads the user's ID and claims from it
- The server checks whether this user may do this action
- The server performs the write
Typical server-side work includes setting a user's role, marking a subscription active after a Stripe webhook, granting credits, approving an application, and sending a notification to another user.
Two mistakes I find often in AI-built apps. The first is the service account key placed in a variable with the NEXT_PUBLIC_ prefix, which publishes full admin access to the world. That key belongs in a server-only environment variable. The second is a server route that performs an admin write without verifying the caller's token, which is an open rule with extra steps.
How do roles work in security rules?
Store the role where users cannot write it, then have the rules read it from a custom claim or from a server-written document.
Custom claims
The server sets a claim with the Admin SDK, and rules read it as request.auth.token.role == 'admin'. Claims cost nothing to read and cannot be edited by the user. The catch is that a changed claim takes effect when the user's token refreshes, so a role change is not instant unless you force a refresh.
Role documents
Rules can look up another document with get(), for example reading the role field from the user's own document under /users. This updates instantly, but each lookup is billed as a read, and the role document must itself be locked against user writes.
On Guardian MindCare, a therapy practice platform I built on Firebase, there are five roles: therapists, supervisors, trainees, clients and admins. The permissions are set so each role sees only what it should, and that is only possible because the role is something the user cannot change.

With several roles, write the rules per collection as short sentences first: "a client reads only their own appointments, a therapist reads appointments where they are the therapist, an admin reads all." Then translate each sentence into a rule. It is much easier to review English than rule syntax.
How do I secure Firebase Storage uploads?
Give Storage its own rules: put private files under a path that contains the user ID, check that ID, and limit size and file type.
Storage rules live in a separate file, storage.rules, and are forgotten more often than Firestore rules. The same open patterns apply, so search for them there too.
A working layout:
- Private uploads under /users/{userId}/, with read and write allowed only when request.auth.uid == userId
- A size limit on write: request.resource.size < 5 * 1024 * 1024 for five megabytes
- A type limit: request.resource.contentType.matches('image/.*') for images only
- Public assets such as product photos in a separate folder with public read and no client write
Without a size limit, anyone with an account can fill your bucket and you pay for the storage and the downloads. Without a type limit, your bucket can end up hosting files you never intended to serve.
Remember that download URLs containing a token work for anyone who has the link, regardless of rules. For sensitive documents, do not store those URLs in places other users can read.
How do I test rules before launch?
Try every collection as three people: the owner, a different signed-in user, and a signed-out visitor.
Rules Playground
In the Firebase console, the Rules tab has a Playground. Choose get, list, create, update or delete, enter a document path, switch authentication on or off, set a user ID, and run it. It shows whether the request is allowed and which line decided.
The emulator
For anything beyond a few checks, run firebase emulators:start and point your app at the local emulator. You can sign in as test users and try real flows without touching production data. The rules unit testing library lets you write these checks as automated tests.
A worked test
Create two accounts, A and B. Signed in as B, try to read A's profile, list all orders, update A's order, and set your own role to admin. Signed out, try to read anything. Every one of those should fail. Then, as A, confirm your own reads and writes still work. When it all passes, deploy with firebase deploy --only firestore:rules,storage and confirm the console shows the new version.
The final checklist:
- No rule allows everyone to read or write, and no test-mode date remains
- No rule relies on sign-in alone
- Every user document checks ownership on read, create and update
- Users cannot edit their own role, plan or balance
- Admin actions run server-side behind a verified token
- Storage paths are checked by user ID, with size and type limits
- Rules tested as a second user and as a signed-out visitor
If you would rather have someone else do this pass, I review and fix Firebase rules as part of my work on AI-built apps. A single rules problem is a Quick Fix from $60, and a full pre-launch pass with auth, payments and deployment is the Finish and Launch package from $600.
What are the Firestore best practices for cost and performance?
Design queries so each screen reads a small, predictable number of documents, because Firestore bills by the document and slows down on hotspots.
Google's Cloud Firestore best practices page and billing page give the rules I build around:
Reads are the bill
Firestore charges for each document read, written and deleted, and its billing page says a query that returns nothing is still charged a minimum of one read. A home screen that loads 300 documents for every visitor costs 300 reads per visit. Load the 20 the screen shows.
Paginate with cursors, not offsets
The best practices page says not to use offsets. Documents skipped by an offset are still retrieved and billed. Use startAfter with the last document of the previous page instead.
Keep listeners narrow
A realtime listener re-reads documents as they change, so a listener on an entire collection of orders is a running meter. Listen to a filtered, limited query, such as this user's open orders, and detach listeners when the screen unmounts.
Avoid hotspots
Google recommends automatic document IDs, because sequential IDs such as Customer1, Customer2, Customer3 can create hotspots that hurt latency. The same page warns that one document updated at high rates will hit contention, so a single global counter that every user increments is a design to avoid. Use a distributed counter or aggregate on the server.
Trim indexes you never query
Firestore indexes every field by default. The best practices page suggests index exemptions for large string fields and for fields you never filter on, which saves storage and write cost.
Which Firebase best practices matter beyond security rules?
Rules come first, but Google's own Firebase launch checklist adds a few project settings that take minutes and prevent the next most common disasters.
- Separate projects. The checklist recommends different Firebase projects for development, testing and production. Testing a migration against live data is how real records get deleted.
- Budget alerts. Set them in the Google Cloud console before launch. The checklist is clear that alerts are not budget caps, so a runaway loop can still spend money; alerts just tell you quickly.
- App Check. Turn it on and move to enforcing for every service that supports it, so requests must come from your real app rather than a script using your config.
- Restricted API keys. Limit each key to the APIs it actually needs.
- Unused sign-in providers. Disable any you do not use, especially anonymous auth, and add only your production domains to the authorized domains list.
- More than one owner. If the only owner account belongs to a contractor who disappears, so does your access.
None of these replaces correct rules. App Check stops casual abuse of your config, but a determined attacker with a valid session is still limited only by what the rules allow.
The bottom line
Your Firebase config is public, so your rules are your security. Remove every open and test-mode rule, tie each document to its owner, name the fields users may change, move anything sensitive to server code using the Admin SDK, give Storage the same care as Firestore, and test as someone who should be refused. An afternoon spent here is far cheaper than explaining a data leak to your first customers.
Questions, answered in one line
What does Firebase test mode do?
It allows anyone to read and write the database until a set date, which is fine for a prototype and dangerous after launch.
Is the Firebase config in my frontend a secret?
No. It identifies your project and is public by design, so security rules are what protect your data.
How do I test security rules?
Use the Rules Playground in the Firebase console or the local emulator, signed in as different test users.
Is "allow read, write: if request.auth != null" secure enough?
No. It lets any signed-in user read and change every document, and anyone can create an account, so it protects very little.
Do Firestore rules apply to the Admin SDK?
No. The Admin SDK bypasses security rules, which is why it must run only on a server or in Cloud Functions and never in the browser.
Do rules on a document cover its subcollections?
No. A match on a document does not apply to the collections beneath it, so each subcollection needs its own rule.
Sources
- Avoid insecure rules Firebase
- Firebase launch checklist Firebase
- Firebase App Check Firebase
- Best practices for Cloud Firestore Firebase
- Understand Cloud Firestore billing Firebase
- Control Access with Custom Claims and Security Rules Firebase
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
- Firestore "Missing or insufficient permissions": what triggers it and how to fix it
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