Your business app shows the correct customer records to the correct employee. That does not prove its database is safe. A mobile client can issue a direct Firestore query outside your visible screens. Before launch, test what the data layer allows, especially when several companies use the same app.
Firebase's Security Rules documentation explains that rules control access for mobile and web clients, and that broad matching rules can accidentally grant access even when a narrower rule appears restrictive. Firebase's emulator guide recommends unit tests against the local emulator to check the behaviour you expect.
Start with an access matrix
For each collection, write the actors and allowed actions: unauthenticated visitor, staff member, manager, organisation owner and internal service. Include reads, list queries, creates, updates and deletes. Add at least one cross-organisation case. A salesperson from Company A should not be able to guess a Company B invoice ID and read it, even if the interface never links to that invoice.
Make ownership explicit in the document path or verified membership data. Do not trust a client-sent companyId alone. Check that a user cannot change an ownership field in an update to move someone else's record into their own tenant. Decide which fields a staff role may edit; a rule that allows any update can let a normal user set approved: true or change a price.
Test both accepted and rejected requests
Use the local Firestore emulator with test accounts representing your roles. Assert that legitimate actions succeed and forbidden actions fail. Run the same cases for list queries as well as individual document reads; a query can be rejected even when a single document read works, depending on how its constraints are expressed. Add a regression test whenever you create a new collection or role.
Firebase's rules testing documentation notes a crucial boundary: server client libraries bypass Firestore Security Rules and authenticate through Google credentials. If your backend reads Firestore on behalf of users, it must enforce tenant membership and permissions itself, while IAM limits what the server identity can do. A green emulator suite for client rules does not certify backend routes.
Review the production rules and rollout
Compare the deployed rules with the version in your repository. A console hotfix that never reaches source control can be overwritten later. Test changes locally, deploy them intentionally, and watch denied-request patterns after launch without logging sensitive payloads. Keep a rollback plan if legitimate users suddenly lose access.
For a clinic, distributor or agency app, the most useful output is a small set of tested access rules tied to actual job roles. If you are unsure whether employees can cross account boundaries, show me the data model at adityazen. I can map the access cases and close gaps before real customer data enters the app.





