Skip to content

feat(cloud): read-only admin dashboard of every account - #100

Merged
teo-goulois merged 3 commits into
mainfrom
t3/cloud-admin-dashboard
Nov 23, 2026
Merged

teo-goulois merged 3 commits into
mainfrom
t3/cloud-admin-dashboard

Conversation

@teo-goulois

Copy link
Copy Markdown
Contributor

What it shows

pnpm cloud:dashboard serves an overview of every Localify Cloud account on the operator's Mac, through Localify:

  • Headline numbers: users, new ones in the last 7 and 30 days, active and serving machines, live and serving URLs, accounts per plan status (override, trialing, active, past_due, canceling, none), add-on units that count, banned accounts and takedowns.
  • New sign-ups per week: inline SVG bars, the last 26 weeks on desktop and the last 12 on a phone.
  • Needs attention: banned and past_due accounts, overrides ending within 30 days, and accounts at 80% or more of their URL, serving-machine or signed-in-machine limit.
  • Users table: sortable, with a search box. Columns: GitHub login, signed-up date, plan or override (reason and expiry), serving machines against the limit, live URLs against the limit as a bar, last activity, banned flag. D1 records no visits, so "last activity" is the latest sign-in, tunnel start, remote key, URL created or deleted, or billing event.
  • A page per account: what cloud:admin show prints, laid out visually: ban, override, billing snapshot, add-ons, entitlement, machines, and each URL with the machine serving it and its state (serving, suspended, suspended until the next reconcile, taken down).

Plans, overrides and add-ons go through src/entitlement.ts (accountOf, servingUrlLimit, signedInMachineCap). The only change there is a new EVERY_ACCOUNT_SQL export: the existing account select, without a WHERE.

Light and dark themes (the system setting, plus a toggle). Data is read when a page loads, cached 30 seconds, with a refresh button (at most one re-read every 5 seconds) and the time of the last read. Plain Node http with server-rendered HTML, no new dependency.

Read-only

  • scripts/dashboard/db.ts refuses, before anything is sent, any statement that is not one plain SELECT. That covers WITH (a CTE can hold a write), ;, unterminated quotes or comments, and write, schema or connection keywords outside string literals. Tests cover the refusal, and check that nothing reaches the database when one statement of a batch is refused.
  • No route takes input that reaches SQL. A user page looks the id up in the cached read. Anything but GET and HEAD gets 405. Only .localify hosts and loopback are answered, which a Localify public URL's traffic arrives as.
  • No query selects a token, a password hash or salt, a tunnel or DNS id, a remote key or an ingress port. A test seeds them as fixtures and checks they are absent from every page. A failed read answers 503 without its error, which goes to the terminal only.
  • Pages are sent with Cache-Control: no-store, a nonce-based CSP, frame-ancestors 'none' and noindex. Every value from D1 is escaped.
  • All reads go out in one wrangler d1 execute --remote call as CLOUDFLARE_DEPLOY_TOKEN from Infisical. Only that token and the account id are kept in memory. A dedicated read-only D1 token in Infisical would be safer than the deploy token; creating it is left to Téo.

How to run it

The README's new "Dashboard" section has the steps:

# once: give apps/cloud its own service and domain in the repo's Localify project
localify project add-service --path apps/cloud --domain cloud-dashboard.<project-id>.localify
# then, from apps/cloud
localify dev cloud -- pnpm cloud:dashboard            # production D1
localify dev cloud -- pnpm cloud:dashboard --local    # the D1 of pnpm cloud:dev
# from a phone: a password-protected public URL
localify public-url create cloud-dashboard.<project-id>.localify

Without the PORT that Localify sets, it refuses to start.

Checks

  • pnpm cloud:typecheck and pnpm cloud:test pass (446 tests, 45 of them new). The new tests cover the SELECT guard, the queries and aggregation against the real migrations with fixture rows, the cache, and the routes.
  • It was run through Localify against a local D1 seeded with made-up accounts, and checked at 390 px and 1280 px wide in both themes. That run also showed that D1 caps the terms of a compound SELECT, which node:sqlite doesn't, so the activity query uses joins instead of a UNION.
  • Not yet checked against production D1: on this Mac, infisical export answers 403 "This project does not belong to your selected organization", so the deploy token could not be loaded. pnpm cloud:admin hits the same error. After switching Infisical to the right organization, run the production command above once.

pnpm cloud:dashboard serves, through Localify, an overview of every
Localify Cloud account: headline numbers, accounts per plan, sign-ups per
week, what needs attention, a sortable users table and a page per
account. It reads D1 in one wrangler call of SELECT statements, cached 30
seconds, and its database layer refuses anything else.
Wrangler ran through spawnSync, so a stalled read froze every request and
the stop signals. It now runs asynchronously, is killed after a minute or
when the dashboard stops, and a failed read is still not cached.
@teo-goulois
teo-goulois merged commit a9bed8d into main Nov 23, 2026
10 of 13 checks passed
@teo-goulois
teo-goulois deleted the t3/cloud-admin-dashboard branch November 23, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant