Skip to content

feat(dashboard): use the official auth/DB foundation (#547 phase A) - #642

Merged
LudoLoops merged 1 commit into
mainfrom
547-phase-a-official-auth-db
Oct 23, 2026
Merged

LudoLoops merged 1 commit into
mainfrom
547-phase-a-official-auth-db

Conversation

@LudoLoops

Copy link
Copy Markdown
Contributor

Phase A — official auth/DB foundation

New Dashboard projects now use the official sv add drizzle better-auth integrations; SVForge only composes its product/security extensions on top. Base projects are unchanged, existing projects are not migrated.

Ownership split

Concern Owner
Better Auth instance/adapter/hooks handler, auth tables + auth:schema, Drizzle client/config, versions official add-ons
Sign-up policy, invite gate, role/disabled (additionalFields, input:false), disabled-session guard, domain tables, admin UI/scripts SVForge
  • svforge create now runs sv add drizzle="database:postgresql+client:postgres.js+docker:no" and sv add better-auth="demo:" before the SVForge add-on (single install at the end).
  • The dashboard template no longer ships auth.ts, db/index.ts, db/auth.schema.ts, auth.schema.config.ts, drizzle.config.ts, hooks.server.ts, app.d.ts, env.ts, .env.example.
  • SVForge applies anchored, idempotent patches: ...svforgeAuthPolicy before plugins + signup mode on the official emailAndPassword; sequence(handleParaglide, handleBetterAuth, handleSvforgePolicy); SIGNUP_MODE in env.ts/.env/.env.example. A missing anchor fails the scaffold loudly.

Security behavior (unchanged)

Closed-by-default sign-up (closed/invite-only/self-service explicit), role/disabled generated NOT NULL by the official auth:schema (additionalFields, input:false), server-side invite gate, disabled identities rejected at session creation and on live sessions via the composed guard, atomic first-admin bootstrap.

Tooling

  • Removed the Better Auth pin, its rewriter and pin tests; the OSV audit resolves the range declared by the installed sv (scripts/better-auth-version.mjs) — CI/publish workflows updated.
  • auth:schema is the official generator and now runs in the scaffold profiles before the DB push/build (the delivered stub is not type-safe before that); svforge create next-steps document the order.
  • Prettier ignores artifacts the official add-ons generate but do not format (tsconfig.json, src/env.ts, src/lib/server/db/auth.schema.ts, drizzle/).
  • check-auth-schema.mjs accepts the official double-quoted output and .defaultNow().

Checks

  • bun run test (whole repository), bun run lint, bun run typecheck, node scripts/check-generated.mjs — pass.
  • bash scripts/test-scaffold.sh base — pass (unchanged base).
  • bash scripts/test-scaffold.sh dashboard (CI=true, disposable PostgreSQL 17) — pass: build, svelte-check, generated ESLint/Prettier, svforge check, 46 template tests, schema↔runtime gate, Better Auth HTTP smoke (setup → closed sign-up rejected → login → admin CRUD → user B sign-in/denied admin).
  • bash scripts/test-scaffold.sh create-cli — pass: svforge create base + all-13-modules dashboard, doctor/check clean, build, 58 tests, real PostgreSQL.

Limitations (by design for phase A)

  • Direct sv add svforge=template:dashboard fails with an actionable message: the published sv cannot conditionally depend on the official add-ons from the dashboard option (phase C, upstream conditional dependsOn).
  • Paraglide remains SVForge-owned (phase B); hooks.server.ts is therefore composed by SVForge around the official auth handle.
  • Existing projects keep their current foundation; no destructive upgrade/migration in this PR.

Refs #547 — phase A only, issue stays open.

New Dashboard projects now compose the OFFICIAL `sv add drizzle better-auth`
integrations instead of SVForge-generated copies. SVForge keeps only its
product/security extensions.

Ownership split:
- `svforge create` runs `sv add drizzle="database:postgresql+client:postgres.js"`
  and `sv add better-auth="demo:"` before the SVForge add-on (single install).
  Direct `sv add svforge=template:dashboard` now fails loudly until the
  official add-ons are present; this limitation is documented (#547 phase C).
- The dashboard template no longer ships auth.ts, db/index.ts,
  db/auth.schema.ts, auth.schema.config.ts, drizzle.config.ts, hooks.server.ts,
  app.d.ts, env.ts or .env.example. `.env`/`.env.example`, `db/schema.ts`
  (domain tables + `export * from './auth.schema'`) and scripts stay SVForge.
- SVForge applies anchored, idempotent patches to the official output:
  `...svforgeAuthPolicy` before plugins plus the sign-up mode on the official
  `emailAndPassword`, `sequence(handleParaglide, handleBetterAuth,
  handleSvforgePolicy)`, `SIGNUP_MODE` in env.ts/.env/.env.example. Missing
  anchors fail the scaffold loudly.

Security behavior unchanged: closed-by-default sign-up (invite/self-service
explicit), `role`/`disabled` via Better Auth `additionalFields` (input:false,
generated NOT NULL by the official `auth:schema`), server-side invite gate and
session rejection for disabled identities, atomic first-admin bootstrap.

Tooling:
- remove the Better Auth pin, its rewriter and pin tests; the security audit
  resolves the range declared by the installed `sv` (`better-auth-version.mjs`).
- `auth:schema` is the official generator; scaffold profiles run it before
  the DB push/build (the generated stub is not type-safe before that).
- Prettier ignores the official/generated artifacts it does not format
  (tsconfig.json, src/env.ts, auth.schema.ts, drizzle/).
- schema gate accepts the official double-quoted output and `.defaultNow()`.

Validated: full repo suite, lint, typecheck; `test-scaffold.sh base`,
`dashboard` (46 tests, schema gate, Better Auth HTTP smoke, closed sign-up)
and `create-cli` (all 13 modules, 58 tests) with real PostgreSQL.

Refs #547 (phase A; Paraglide and direct-add orchestration remain).
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