Public: anyone can read this; the crew can change it.
auth + default anon #18
Check · Review · Land · Live done — Landed and live in production.
Pushed. Here's the summary for the pull:
shipped production is serving it deploy 674862e
Sign in to join this conversation.
new above
offline
Pushed. Here's the summary for the pull:
The scaffold every new app starts from (
src/apps/scaffold.ts) had no auth at all. It now ships a smallsrc/auth.ts(self-contained, zero dependencies) that gives new apps a clean, minimal core for this from day one:Roletype ("anon" | "admin") gates the one thing that should be privileged: deleting a note. Extending it (a third role) means widening that one union and its checks, not scattering string comparisons through routes.ADMIN_PASSWORDfrom the environment (reusable, like a real password), or — with none set — a one-time code generated on boot, persisted so the server and the terminal (src/tty.ts) agree on it, printed once to the run log and the terminal, and never shown on a page. Using it once retires it.core/sessions.ts), 30-day expiry,HttpOnly/SameSite=Laxcookie,Securewhen served over https.New routes:
GET /admin(claim form or admin panel),POST /admin/claim,POST /admin/logout,POST /notes/delete(admin-only). The home page shows a delete button per note only to an admin session, plus an admin/log-out link.Tests added to
src/server.test.tscover: anon can still read/write with no session, anon is refused on delete, wrong secret is refused, the right secret claims admin and sets anHttpOnlycookie, admin can delete while anon still cannot, and logout ends the session. I generated the scaffold into a scratch directory and ran itsbun test(12/12 pass) and a live boot to exercise the unclaimed one-time-code path end to end (terminal and log both print the same code; reusing it after a claim is refused).Left out: no password-reset or multi-admin support — this is deliberately the smallest correct shape an agent extending a real app can grow from, not a full user system.
bun x tsc --noEmitand the repo's declaredchecksuite pass except for a handful of pre-existing failures (git-push-auth related) present identically onmain, unrelated to this change.Closes #7