fragJulia
Changelog

2026-11-21 — Consent records validated on the server; accounts without consent are locked

Rework of the consent migration after the external review in #715. The database now validates the full consent set against registered versions, sets the time itself and locks accounts without valid consents. Not applied to the live database.

Addresses the findings in #715. The issue stays open: legal review and the live rollout are not done.

Findings and what changed

#715 findingChange
P1 — missing or partial consents let throughSignup with a consents key must carry all four types; otherwise the signup is rejected and nothing is created. Signup without the key creates a locked account.
P1 — any version and wrong types produce recordsVersions are checked against the new consent_versions registry; values must be JSON strings equal to the current version. false, numbers, objects, arrays, padded or invented versions and unknown keys are rejected. A foreign key ties every record to a registered version.
P1 — client-controlled timegranted_at is set by a trigger from the server clock for every insert. consents_granted_at is no longer sent or read.
P2 — invalid time aborts signupNo client time is parsed.
No enforcement behind the checkboxesRestrictive RLS policies on 17 tables refuse inserts and updates without valid consents; 16 API routes check before processing; yoga_join_meet() checks itself.
Existing accounts, re-consentgrant_consents() plus a gate in the app. Existing accounts are locked until their owner confirms; no historical consent is invented. A version change locks everyone until they accept the new text.
Explicit rightsNo table grants for API roles beyond SELECT on own records; internal functions not executable by API roles.
Mobile and other clientsMobile register screen asks for the three confirmations and sends the versions; a mobile gate handles locked accounts. Versions shared via packages/shared.
Negative tests42 database cases in apps/web/lib/consent-migration.test.ts, run in CI with the web tests.

Files

  • supabase/migrations/20261121_user_consents.sql replaces 20261119_user_consents.sql, which was never applied anywhere.
  • apps/web/lib/consent.ts, lib/consent-server.ts, components/consent-fields.tsx, components/consent-gate.tsx, app/layout.tsx, app/registrieren/page.tsx, 16 routes under app/api/.
  • apps/mobile/components/ConsentChecks.tsx, ConsentGate.tsx, app/auth/register.tsx, app/_layout.tsx, hooks/useAuth.tsx; packages/shared/src/lib/consent.ts.
  • New dev dependency @electric-sql/pglite (in-process Postgres for the migration tests).
  • Docs: consent records rewritten; go-live map section B and owner list.

Verification

  • Web tests: 208 of 209 pass; the one failure is the study-data staleness check. tsc, eslint (0 errors) and next build pass.
  • Mutation check: with the string-type check, the server-time trigger and the restrictive policy each weakened, 5 of the database tests fail.
  • Live schema, inside a rolled-back transaction: see "Tests" in consent records. Nothing was left behind (no tables, no policies, 4 users as before).

Not verified

  • A real signup through Supabase Auth against the migrated database, including e-mail confirmation.
  • The gate against a real database. It was driven in a browser against a production build with a stubbed backend (desktop and 390 px), and by component tests.
  • The mobile screens on a device or simulator. They are type-checked only; the mobile project has unrelated type errors of its own (voice services, React type versions).

Follow-ups

  • Owner: legal review of the wording; decision to apply the migration (order: deploy code first, then migrate).
  • Run the mobile consent screens on a device before a mobile release.

On this page