Skip to content

feat(prerequisites): versioned legal acceptance; drop phantom endpoints - #12

Merged
thinkclay merged 1 commit into
mainfrom
feat/versioned-legal-acceptance
Aug 5, 2026
Merged

thinkclay merged 1 commit into
mainfrom
feat/versioned-legal-acceptance

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Supports Scaffald/SaaS#519 (versioned terms acceptance).

What changes

PrerequisitesCheckResponse now carries server-resolved legal state, so no client ever embeds a version constant:

field meaning
needsOnboarding profile fields missing → full onboarding form
needsLegalAcceptance profile complete, legal stale → lightweight re-accept screen
legal.documents.* per-doc requiredVersion / acceptedVersion / effectiveAt / url / needsAcceptance

isComplete tightens to !needsOnboarding && !legal.needsAcceptance — acceptance of a superseded version no longer counts, which is what lets a published version bump force re-acceptance with no code deploy.

New: prerequisites.acceptLegal() (POST /v1/prerequisites/accept-legal) and a public Legal resource (legal.getCurrent() → GET /v1/legal) for the logged-out terms/privacy pages.

What is removed

Six methods that mapped to endpoints the server never implemented: list, getById, checkPrerequisite, validate, getMissing, getCompletionStats. They passed tests only because msw mocked them, and were invisible to the SDK↔route contract test because they called super.get rather than this.get. check() now uses this.get, bringing it under contract coverage.

Also deletes src/types/prerequisites.ts, a drifted duplicate of the resource's own types (the barrel now re-exports from the resource).

Verification

  • pnpm build && pnpm test — 764 tests pass; the prerequisites suite is rewritten for the real endpoints (check shape incl. legal state, complete, acceptLegal happy + rejection, legal.getCurrent).
  • SDK↔route contract test in the API repo passes with no KNOWN_GAPS edits.
  • Exercised against a live local API: publishing a new terms version by SQL flips an onboarded user to needsLegalAcceptance: true, and acceptLegal() restores isComplete: true with the new version stamped.

🤖 Generated with Claude Code

The prerequisites check response now carries the server-resolved legal
state so clients never embed a version constant:

  needsOnboarding      — profile fields missing → full onboarding form
  needsLegalAcceptance — profile complete, legal stale → re-accept screen
  legal.documents.*    — per-doc requiredVersion / acceptedVersion /
                         effectiveAt / url / needsAcceptance

Adds prerequisites.acceptLegal() for the lightweight re-acceptance screen
and a public Legal resource (GET /v1/legal) for the logged-out terms and
privacy pages.

Removes six methods that mapped to endpoints the server never implemented
(list, getById, checkPrerequisite, validate, getMissing,
getCompletionStats) — they passed tests only because msw mocked them, and
were invisible to the SDK↔route contract test because they called
super.get. check() now uses this.get so it is covered.

Co-Authored-By: Claude Fable 5 <[email protected]>
@thinkclay
thinkclay merged commit e4a47e5 into main Aug 5, 2026
@thinkclay
thinkclay deleted the feat/versioned-legal-acceptance branch August 5, 2026 19:51
thinkclay added a commit to Scaffald/SaaS that referenced this pull request Aug 5, 2026
This branch pinned packages/sdk and packages/ui at the tips of
Scaffald/sdk#12 and Scaffald/ui#17. Both were squash-merged, which creates a
new commit and leaves the branch tips unreachable from their mains — so the
pointers here referenced commits that no longer exist on any branch. Merging
in that state would have pinned SaaS main to orphaned submodule commits.

  packages/sdk  f96f4180 -> e4a47e5 (sdk main, #12 squashed)
  packages/ui   39f950d1 -> fdaa0d4 (ui main, #17 squashed)

Verified the squashed commits carry what this branch needs — sdk has
resources/legal.ts and prerequisites' needsLegalAcceptance, ui's Checkbox
forwards testID — and that scf-core typechecks clean against them.
thinkclay added a commit to Scaffald/SaaS that referenced this pull request Aug 5, 2026
…ce, web PKCE (#519)

* fix(auth): keep the auth Stack mounted during the session check so OAuth callback tokens survive

The (auth)/auth layout returned a Loading view *instead of* its <Stack>
while useProtectedRoute was pending — which is always the case on first
render. With the navigator unmounted during hydration, react-navigation
resolved the focused route back to the group's initial route and
expo-router's history sync rewrote the URL to /auth, destroying the
#access_token fragment on /auth/callback ~5ms before supabase-js
initialized and read the URL. Result: every web OAuth login (Google/
Apple) on prod silently bounced back to the login screen.

Render the Stack unconditionally and overlay the loading state instead.
Verified end-to-end against a local dev server: minted a real GoTrue
session, loaded /auth/callback#access_token=... — supabase-js now issues
the /auth/v1/user validation call, stores the session, and lands on
/dashboard signed in. Before the fix the same URL produced zero auth
requests and a silent bounce (reproduced on prod with an instrumented
iframe probe).

Also add the apex + www domains to the local config.toml redirect
allow-list and fix its stale production comment (prod's hosted
uri_allow_list already had them).

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(auth): versioned legal acceptance, passive login notice, layout hydration fix, web PKCE

Four related auth changes.

1. Versioned legal acceptance (migration 342)

core.legal_documents holds one is_current row per document type and is the
single source of truth for which version users must accept. It replaces
five drifting hardcoded version constants (login screen, cookie provider
x2, both prerequisites routers, the document page subtitles). Publishing
new terms is now an UPDATE+INSERT documented in the migration header — no
code deploy.

GET /v1/prerequisites/check reads it and reports which gate, if any, is
unresolved: needsOnboarding (profile fields missing -> full onboarding
form) or needsLegalAcceptance (profile complete, legal stale -> the new
lightweight /legal-update screen). Acceptance now only counts at the
current version, so a version bump forces re-acceptance; the seeded
current version is 'v1.0', which every existing preferences row already
carries, so nobody is re-prompted at cutover and no data migration is
needed.

POST /v1/prerequisites/accept-legal backs the re-acceptance screen. Both
it and /complete stamp versions read from the table and write
consent_records audit rows server-side, with first-class
'terms_of_service'/'privacy_policy' consent_type values (CHECK extended)
instead of the previous metadata.type shoehorn.

2. Login screen: passive notice replaces the consent checkbox

The checkbox was theater: a SIGNED_IN listener wrote two consent_records
rows unconditionally, without consulting it, on web and native alike. That
client-side write is deleted. The notice is browsewrap; the real
versioned, audited clickwrap now happens in onboarding and /legal-update.
Adds i18n keys in en/es/fr (the old copy was hardcoded English).

3. (protected) and (admin) layouts: same hydration bug as the OAuth callback

Both rendered <Slot /> only once ready, so during web hydration the
navigator was unmounted and expo-router rewrote the URL to the group's
initial route — the mechanism that ate the OAuth callback hash in the
previous commit, here eating deep-link paths. Both now keep the navigator
mounted behind an opaque overlay, which also closes a one-frame flash of
protected content before a redirect. Redirect refs became target-aware so
a user can move between gates without getting stuck.

4. Web OAuth switched to PKCE

flowType is pkce on web (native keeps implicit; it signs in via
signInWithIdToken and never parses URLs). A pkce client rejects
implicit-style #access_token callbacks AND calls _removeSession on the way
out, which is what GoTrue's {{ .ConfirmationURL }} email links produce —
so the email templates now link to a new flow-agnostic /auth/confirm
route that verifies a token_hash. See the deploy-order constraint in
client.ts: hosted templates must be updated and old links allowed to
expire before a build with this flag ships.

Also removes dead code: PrerequisiteWidget (rendered nowhere, validated
legal fields it never rendered) and the SDK's six phantom prerequisites
endpoints; fixes extensionless edge-function imports that broke
`supabase functions serve` for the whole stack; and reconciles the
three-way testID drift between the onboarding form, the Playwright
helpers, and tests/TEST_IDS.md.

Verified against a live local stack: 8 new Deno route tests cover the
check/complete/accept-legal contract including the stale-version round
trip and its audit rows. Manually exercised a real version publish — an
onboarded user flipped to needsLegalAcceptance with needsOnboarding still
false, then accept-legal restored isComplete with the new version
stamped. Unit suites (scf-core 304, SDK 764, root-route 23, schemas 53)
and the SDK/route contract test pass; typecheck clean.

Co-Authored-By: Claude Fable 5 <[email protected]>

* chore(auth): hold the web PKCE flag for a follow-up deploy

The flowType flip and the /auth/confirm route were in one commit, which
made every web deploy of this branch order-dependent: shipping the flag
before the hosted email templates are updated (and before links issued
under the old templates expire) breaks magic-link sign-in AND signs the
clicking user out, because a pkce client rejects the implicit-style
#access_token callback and _initialize() then calls _removeSession().

Dropping just the flag makes this branch safe to deploy in any order. The
/auth/confirm token_hash lander and the template changes still ship here —
they are flow-agnostic and are the prerequisite for the flag. The flip
follows once templates are live and old links have expired.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(legal): format effective dates in UTC

effective_at is stored as midnight UTC, so formatting it in the viewer's
local timezone shifted it a day backwards for anyone west of UTC: the
terms page rendered "Last updated: February 2025" for a document that took
effect 2025-03-01. Caught on the dev deploy.

Adds a shared formatEffectiveDate() so the document pages and the
re-acceptance screen cannot drift on this again. The effective date is a
legal fact, not a local timestamp.

Co-Authored-By: Claude Fable 5 <[email protected]>

* chore(submodules): repoint at the squashed sdk/ui mains

This branch pinned packages/sdk and packages/ui at the tips of
Scaffald/sdk#12 and Scaffald/ui#17. Both were squash-merged, which creates a
new commit and leaves the branch tips unreachable from their mains — so the
pointers here referenced commits that no longer exist on any branch. Merging
in that state would have pinned SaaS main to orphaned submodule commits.

  packages/sdk  f96f4180 -> e4a47e5 (sdk main, #12 squashed)
  packages/ui   39f950d1 -> fdaa0d4 (ui main, #17 squashed)

Verified the squashed commits carry what this branch needs — sdk has
resources/legal.ts and prerequisites' needsLegalAcceptance, ui's Checkbox
forwards testID — and that scf-core typechecks clean against them.

* fix(work-logs): select team_id, which WorkLogRow requires

`pnpm build` failed on this branch with TS2741 at work-logs.router.ts:900 —
fetchWorkLog declares Promise<WorkLogRow> but WORK_LOG_SELECT never asked for
team_id, so the returned row was missing a field the regenerated DB types make
required.

Pre-existed the submodule repoint in the previous commit; verified by checking
out HEAD~1 and reproducing the same error. Blocking the push, so fixed here.

* style(api): satisfy `deno fmt --check` on the prerequisites/legal routes

The "Lint REST API Code" job runs `deno fmt --check`, which this branch's three
new/changed files did not satisfy: routes/prerequisites.ts and the legal and
prerequisites route tests. Mechanical; no behavioural change.

---------

Co-authored-by: Claude Fable 5 <[email protected]>
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