Realtime Database
Since v2.3.0Security rules and Read as a user
Fuego opens the security rules of a Realtime Database on every plan to read and copy, and on a paid plan checks and applies changes after a side-by-side review, with version history and emulator coverage. Switch any tab from Admin to a user or an unauthenticated visitor with Read as to test your rules live.
Security rules
Open the rules
The security rules of a database decide who can read and write each part of it from your app. Open them in Fuego, on every plan, from:
- Tools ▸ Security rules… on the Realtime Database page;
- Security rules… in a database’s ⋮ menu (Database actions);
- Security rules… in the command palette.
Fuego reads the rules as the database holds them, always with the project’s own credentials. On the Free plan you can read and copy them; checking and applying a change needs a paid plan (Individual, Team or the Lifetime Deal).
At the top of the dialog are History, Copy, Open in the Firebase console and the Editor / Changes switch (Changes shows In the database next to Yours). At the bottom are Close, Reset, Check and Apply….
Check the rules
Check sends the editor’s rules to the database to be validated without applying them (including on a database kept read-only in Fuego). It either confirms that no problem was found, or lists each problem’s line, column and message—click a problem to jump to that line.
Apply a change
- Edit the rules in Editor.
- Click Apply…. Fuego checks the rules first; if there are errors, nothing is applied.
- The review (Apply these rules?) shows the rules In the database next
to Yours, and reminds you that
firebase deployfrom a project folder overwrites these rules with that folder’s rules file. - Click Apply.
When the rules changed in the database
Fuego applies your rules only when the rules in the database are still the ones you started from. If someone changed them meanwhile, Fuego applies nothing and shows two comparisons—Your changes and Changed in the database—so you can choose Start from the rules of the database or Overwrite with mine.
History
History lists the versions of the rules Fuego kept for this database, newest first:
- Applied: rules applied from Fuego;
- Before: the rules an apply replaced.
Fuego keeps the 50 newest versions of each database, and always the first rules it ever replaced there. Select a version to compare it with the editor, and on a paid plan click Restore into the editor (nothing is applied until you click Apply…). With settings sync on, the 10 newest applied versions and the oldest “before” version (up to 512 KB each, excluding emulator projects) sync to your other computers.
Add a missing index
When a query ordered by a child fails with This query needs an index,
clicking Add the index… opens this dialog with the .indexOn rule added in
place:
- On a paid plan, Fuego checks the result so you can review and apply it, then re-runs the query automatically.
- On the Free plan, Changes previews the result and Copy ▸ The index rule copies the snippet.
On the emulator
For a database of an emulator project (paid plans), Fuego
reads, checks and applies the rules of the running emulator only; your local
database.rules.json file is not modified.
Rules coverage
On an emulator database, Show coverage highlights which rules the emulator evaluated since the rules were last applied:
- Each rule is tinted and underlined by what it evaluated to (only
true, onlyfalse, both, another value, or never evaluated), with its evaluation count at the end of the line and on hover. - A summary above the editor shows how many rules were evaluated, with Refresh and Hide coverage.
- Requests made as Admin are not counted by the emulator: switch a tab to a user or visitor with Read as and browse the data to see those evaluations counted.
When the rules cannot be changed
The dialog explains why at the top when the editor or Apply… is disabled: on the Free plan, with a read-only team sublicense, on a project or database kept read-only in Fuego, on an unverified database synced from another computer, or when the rules exceed 10 MB. When your Google Cloud account lacks the required IAM role, a failed check or apply opens the IAM permissions required dialog (Access to Google Cloud).
Read and write as a user
Fuego reads as Admin by default, using the project’s credentials, so security rules do not apply. Read as switches a single tab to a signed-in user of your app (with the token claims you choose) or to an unauthenticated visitor, so the database checks every read—and, on a paid plan, every direct edit—of that tab against your security rules.
Reading as a user works on every plan; writing as a user needs a paid plan.
Choose who a tab reads as
Click the identity badge in the tab’s toolbar (As: Admin, As: Unauthenticated or As: {name}) and choose:
- Admin: reads with the project’s credentials; rules do not apply.
- Unauthenticated: reads as a visitor who is not signed in (
auth == null). - User: reads as a signed-in user with the
uidand token claims you specify.
Each tab has its own identity, so two tabs on the same node can read as two different people. A non-Admin tab highlights its badge and top border in orange.
Pick a user and token claims
With User, search a user from your project’s
Firebase Authentication by email, name, phone number
or uid, or type any uid directly.
Token claims accepts a JSON object for auth.token. For a user picked from
the list, Fill from the user pre-fills the standard sign-in claims (email,
email_verified, firebase.sign_in_provider, etc.) and the user’s custom
claims, which you can edit to test roles:
{
"email": "alice@example.com",
"email_verified": true,
"firebase": { "sign_in_provider": "password" },
"admin": true
}
When the rules refuse a read
Remember that Realtime Database rules are not filters: if a user is not allowed
to read /orders as a whole, /orders is refused even when /orders/alice is
readable on its own. When the rules refuse a read, the tab shows Refused by
the database rules and offers Read as Admin or Change identity.
What follows the tab’s identity vs Admin
- Follows the tab’s identity: the Tree, Panel, Table and Raw JSON views, key searches, filters, queries, Count children, Preview the children and Live updates.
- Always runs as Admin: the sidebar’s key list (Keys as Admin), nodes opened in another window or in quick view, background activities/jobs (Export, import and bulk jobs), saved workspaces (tabs reopen as Admin) and dashboard widgets.
Write as a user
On a paid plan, changes made directly from a tab that reads as a user or visitor (Save as {identity} in the details panel or table cell, adding a child, deleting, copying, moving or renaming a node in one request) are checked against your security rules. If the rules refuse a save, Save as Admin… lets you apply the change with the project’s credentials instead.
Compare two identities
To compare side by side what Admin and a user can read at the same node:
- In an Admin tab, right-click the node and choose Compare ▸ Select for comparison.
- Switch the tab to the user with Read as.
- Right-click the node again and choose Compare ▸ Compare with {node}.
From the command line
fuego rtdb supports reading and writing as a user with --as user:<uid>
(plus --claims '{"admin":true}') or --as unauthenticated: see
Command line.
