feat: fold auth into the default template as a gallery card, drop saas#1040
Conversation
|
Design: where the folded-in auth surface lives, and why A few decisions worth writing down before the diff lands, since the issue left the layout open. Auth is a gallery card under createAuth config + password hashing live in Schema: The server-actions greet demo now does real auth. Per the issue, |
The saas template was the default UI template plus auth. Collapse to one UI template by shipping auth as a gallery card (app/features/auth + modules/auth + app/api/auth), styled in plain Tailwind like every other card, and remove --template saas and saas-template.js. The users table gains a passwordHash column in the UI template; gallery:clear strips it (and the auth card) back to the minimal base.
Replace the signedOut-from-input simulation in require-auth.server.ts with getCurrentUser(ctx.request) reading the signed session cookie (the RPC POST is same-origin so it rides along). The 401 is now real: an anonymous caller is genuinely denied. Drop the signedOut flag from greet.server.ts and the simulate checkbox from greeter.ts, and update greet.test.ts to prove denial + an authenticated success path via a real login.
Drop saas from the template lists (gallery-coverage, runtime, template validation), retarget the auth + dashboard + current-user assertions to the full-stack auth card's new paths (app/features/auth, modules/auth), and delete the obsolete saas ui-hygiene test plus the now-orphaned lean-copy.js helper.
05b715f to
647cb99
Compare
Update AGENTS.md, README, the docs site (getting-started, ai-first, auth, cache), the website templates section (3 cards to 2, rename the API card to a clear Backend title noting it ships Drizzle + a backend gallery), and the skill references. Auth is now presented as a full-stack gallery card, not a separate --template saas.
Remove the saas template from the create-webjs wrapper's TEMPLATES + usage, the cli/ui package docs, the blog's agent rule files + CONVENTIONS, the scaffold-sync skill, and the scaffold-strip test's template matrix. Auth is a full-stack gallery card now.
Address self-review: note the server-actions greet demo's dependency on the auth card (at the import site and on the card page), fix the 'three templates' count in the CLI help banner + comment, drop the dead lean-copy re-export from ui registry/extract.js, and correct the saas-template.js path in the start-work skill.
vivek7405
left a comment
There was a problem hiding this comment.
Went through the whole diff with a focus on the gallery:clear regex, the auth-card wiring, and any stale saas leftovers. The core is solid: the passwordHash strip regex matches exactly what the generator writes and no-ops on the api schema, the protected-route gate + createAuth paths are consistent, and invariant 1 holds (no server-only util reaches a browser-shipping page). Five things worth fixing, all now addressed in d0ccc327: the server-actions demo's new hard dependency on the auth card was undocumented at its own surface; the CLI help still said 'three templates'; and a few stale references (the deleted lean-copy re-export, the start-work skill's saas-template path) survived the sweep.
vivek7405
left a comment
There was a problem hiding this comment.
Second pass, narrowed to the risky edges: the gallery:clear + regenerate round-trip (the passwordHash/todos strip produces a valid schema; the leftover uuidPk/bool imports are unused but harmless and pre-date this PR), the unbunified static auth tests (node:test/assert/crypto only, all Bun-fine), the counterfactual strength of the retargeted scaffold assertions, app/api ownership vs clear, and the nullable passwordHash typing. All hold. Clean.
Every gallery feature demo under /features/* now gets a slim '← Gallery' link via a shared app/features/layout.ts, so no card is a dead end. Drops the now-duplicate link from the auth dashboard sub-nav (the features layout provides it).
Mirror the features layout with app/examples/layout.ts so the todo example (and any future example app) gets the same '← Gallery' link. gallery:clear removes it with the app/examples tree.
renderStream() / <webjs-stream> (element-level surgical DOM updates, #248) was only demoed as a secondary button inside the WebSockets card. Add a dedicated card at app/features/stream + modules/stream showing append / prepend / replace / remove / update by target id, registered in FEATURES, pruned by gallery:clear, and covered by the scaffold tests.
The api template now ships its own gallery:clear (clear-api-gallery.mjs) so its backend-features showcase can be shed in one command, matching the full-stack gallery reset. It removes app/api/features, modules/widgets, env.ts, and the widgets test, and strips the features block from the root app/route.ts, keeping the health + users baseline. Covered by a scaffold test (with a counterfactual on the route reset) and noted in the getting-started docs.
vivek7405
left a comment
There was a problem hiding this comment.
Reviewed the additions on top of the auth work: the card, the api-template gallery:clear, and the shared back-to-gallery layouts. The renderStream payloads are well-formed and the plain-field (non-signal) counter correctly keeps render() from reconciling the surgical DOM mutations away; the api features-strip regex matches only the features block's own closer against the real generated route.ts (endpoints stays valid TS) and the removal set matches exactly what api-gallery emits; the nested layouts wrap cleanly with one back-link above the dashboard sub-nav. Clean.
Closes #993
Closes #1041
Summary
Collapse the two UI scaffolds into one. Auth becomes a self-contained gallery card in the default full-stack template, and the separate
--template saasis removed. A fresh full-stack app carries a real, promotable auth baseline (auserstable withpasswordHash,createAuth(), login/signup, a signed session, and a genuinely protected route), andgallery:clearstrips the whole auth surface back to the minimal base.The PR also bundles a set of related scaffold-polish items surfaced while reviewing the generated apps (see "Bundled scaffold improvements").
Core change (#993)
packages/cli/templates/gallery/app/features/auth/(login, signup, a protecteddashboard/subtree gated bymiddleware.ts) plusmodules/auth/(createAuth config, scrypt hashing, signup action, current-user query) plusapp/api/auth/[...path]/route.ts(stays at the app root because createAuth hardcodes/api/auth/*) plustest/auth/auth.test.ts. Styled in plain Tailwind like every other card.isSaas, addpasswordHashto the UIuserstable, shiptest/from the gallery, register the Auth card, remove thehomeAuthLinkssplice and thewriteSaasFilescall. Deletedsaas-template.jsand the orphanedlean-copy.js.TEMPLATESand all usage/help/error text drop saas (webjs.jsplus thecreate-webjswrapper).getCurrentUser(ctx.request)instead of thesignedOutsimulation; the 401 is real.gallery:clearprunes the whole auth surface plus thepasswordHashcolumn back to the exact minimal base.Bundled scaffold improvements (same PR)
gallery:clearfor the api template (Closes Add gallery:clear to the api template to shed its backend-features showcase #1041):clear-api-gallery.mjssheds the backend-features showcase (app/api/features,modules/widgets,env.ts, the widgets test) and strips thefeatures:block from the rootroute.ts, keeping the health + users baseline. Both templates now reset in one command.app/features/layout.tsandapp/examples/layout.tsgive every feature card, the auth pages, the dashboard, and the todo example a← Gallerylink (no per-page edits;gallery:clearremoves them with their trees).<webjs-stream>card atapp/features/streamplusmodules/stream(element-level surgical DOM updates, Add a stream-action protocol with HTTP and live-channel delivery #248), previously only demoed as a button inside the WebSockets card.Test plan
test/scaffolds/*45/45,packages/cli/test/**28/28,test/service-worker/*12/12, ui registry 18/18, scaffold-strip 2/2.webjs checkplustypecheckclean; boots (home,/features/auth, login, signup 200; dashboard 302 to login; then 200 "Welcome" after a real signup). Migrated DB:auth.test.ts2/2,greet.test.ts4/4. The<webjs-stream>card verified live in a real browser (append / prepend / replace / remove / self-remove all apply; 0 stray elements).webjs checkplustypecheckclean;gallery:clearsheds the showcase, the cleared app boots (health/users 200, removed route 404) and passeswebjs check.gallery:clear(full-stack): full reset, schema reverted, boots 200, check clean; removes the features plus examples layouts too.--runtime bunfull-stack app and ran the whole auth flow ON Bun (scrypt,bun:sqlite, createAuth session), the gallery layouts, andgallery:clearunderbun, all green.Doc surfaces