--- id: 10-auth-signup-migration epic: dsr-consent-and-cookie-banner title: auth signUp anonymous consent migration type: technical-story status: done feature: auth depends-on: [04-core-consent-implementation] blocks: [11-documentation] created: 2026-05-19T12:00:00Z updated: 2026-05-19T21:56:58.992Z --- ## Goal Extend the template's `auth.signUp` use case to call `extractAnonymousConsent` + `migrateAnonymousConsent` when a `__consent_state` cookie is present, so a user's pre-signup banner choices persist into their account automatically. ## Why Without this integration, anonymous users who consented via the banner before signing up would lose their consent state at account creation — forcing them to re-consent or leaving analytics gated incorrectly. The migration call is the canonical example for downstream consumers implementing the same pattern in their own `signUp` use cases. ## Done when - `auth.signUp` use case calls `extractAnonymousConsent(cookieHeader)` after user-record creation; if a `__consent_state` cookie is present, calls `migrateAnonymousConsent({ userId, cookieState, bannerVersion, policyVersion })`. - Response includes `Set-Cookie: __consent_state=; Max-Age=0` to clear the anonymous cookie after migration. - `auth.signUp.use-case.test.ts` covers: mock cookie header present → `migrateAnonymousConsent` called with correct args → audit entry has `method: "signup-migration"` → response cookie cleared; no cookie present → `migrateAnonymousConsent` not called. - `RecordingConsent` from `core-testing` is used for assertions (not a raw mock). - `pnpm typecheck && pnpm lint && pnpm test && pnpm conformance && pnpm fallow:audit && pnpm coverage:diff` all pass. ## In scope - `packages/auth/src/use-cases/sign-up.use-case.ts` — add `extractAnonymousConsent` + `migrateAnonymousConsent` calls. - `packages/auth/src/use-cases/sign-up.use-case.test.ts` — extend with migration scenarios. - Auth feature's DI binders — inject `IConsent` dependency when present (guard with `?.` for consumers who haven't installed `core-consent`). ## Out of scope - Anonymous consent storage in `users.consentState` directly from the banner — anonymous state lives in the cookie until this migration. - Post-migration analytics re-initialization — consumer's responsibility via `onConsentChange` callback. ## Tasks - [x] Extend `auth.signUp` use case to call `extractAnonymousConsent(cookieHeader)` + `migrateAnonymousConsent({ userId, cookieState, bannerVersion, policyVersion })` when a `__consent_state` cookie is present, set `Set-Cookie: __consent_state=; Max-Age=0` in the response, and inject `IConsent` into the use case deps (optional, guarded with `?.`); extend `sign-up.use-case.test.ts` with `RecordingConsent` to assert migration call shape, audit entry `method: "signup-migration"`, and cookie-clear; all gates pass.