Skip to content

[Task] F2: guard protected queries through session restoration and account changes #14

Closed

Description

@DavidVFitzGerald

Delivery phase

Phase 1 - frontend with mock services

Goal

Prevent protected frontend data leaking during auth resolution, failures, logout or account switching.

Context and authority

Milestone F2; read AGENTS.md, docs/team/product-manager.md, docs/product/LCA_diff_PRD.md, docs/engineering/roadmap.md, and docs/engineering/LCA_diff_Implementation_Specification.md §§6.1, 6.8, 7.4. Current planning baseline is on docs/agent-workflow, pending review/merge into main; proposed ADRs are not accepted authority. Implement app auth/session controller and query gating/cache reset under apps/frontend/src/app/, keeping transport in services. These application paths are planned until created. Exclude all archive/reference folders.

Requirements and constraints

Resolve auth before deciding whether to show the login dialog. Protected queries require observed verified auth. Clear sensitive rendered state and query caches on logout/identity change/revocation; handle mock 401/403/EMAIL_NOT_VERIFIED safely. Do not delete future account-scoped saved workspace on signout; F5 owns workspace restore.

One session-sized task/PR including verification and handoff. Run all development, installation and checks in containers; install nothing on the host. No real backend, Firebase project, cloud credentials or proprietary inputs. If the current PRD/spec must change, prepare an ADR and updates to both current documents in the same PR.

Acceptance criteria

  • AC1 - A returning valid simulated session shows only non-sensitive loading shell until resolved, then unlocks without a login-modal flash.
  • AC2 - Unauthenticated/unverified/resolving states make zero protected catalog/comparison requests; confirmed anonymous state opens the required modal.
  • AC3 - Logout, expiry, revoked session, failed refresh and auth failures remove protected rendered content, cancel in-flight work and clear prior account query data.
  • AC4 - Switching account A to B cannot display A's cached content or reuse A's pending responses; stale responses cannot repopulate protected UI after logout.
  • AC5 - Unit/component/browser cases prove these transitions; signout does not destructively delete the account-scoped workspace namespace reserved for F5.

Out of scope and follow-ups

Persisted comparison workspace behavior is F5; real token refresh/revocation/Admin verification remains Phase 2. Do not store secrets or claim a mock guard enforces real authorization.

Verification plan

Inside ./dev shell, run format:check/lint/typecheck/test:unit/build and npm --prefix apps/frontend run test:e2e. Instrument mock service calls and delayed responses to prove zero protected calls/late-response rejection and cache isolation.

Engineer records branch/SHA and exact results, leaves issue open, and hands off to QA. QA verifies every criterion at that SHA and reports PASS/FAIL/BLOCKED; mock evidence is not proof of real security/integration.

Dependencies and readiness

Blocked by #11, #12. No implementation until dependencies and the M1 environment runtime gate are satisfied. This body is groomed planning material, not PM READY while blockers remain. Coordinator/PM rechecks merged dependencies and session-sized scope before starting.

Current readiness — supersedes historical planning baseline/blockers above

PM: READY for Phase 1/F2 on merged main at d05e6823cf413f398eeba513a852eb18dd3cadb5. Dependencies #11 and #12 are closed after independent QA PASS, required hosted quality SUCCESS and explicit maintainer merges of PR #45 (f70420d) and PR #46 (d05e682). M1/M2/F1 prerequisites remain satisfied. Current merged documents/contracts replace the historical planning-branch statements above. AC1–5 are unchanged; no new ADR/product decision is required.

The merged baseline already contains createSessionStore, guardDataService, useAuthState, query helpers and provider composition under apps/frontend/src/app/; review and extend their behavior rather than create a parallel controller. Own service-context/queries/ApplicationProviders and focused lifecycle/query tests. #13 owns extraction/replacement of the App LoginDialog, forms, styles and form browser tests; avoid concurrent App edits. Prefer controller/context integration that existing useAuthState and services.auth consumers can use unchanged. Coordinate any minimal callback/API change with #13 and coordinator before implementation.

Preserve the no-login-flash resolving shell and verified-only calls. Treat protected auth failures (AUTH_REQUIRED, EMAIL_NOT_VERIFIED, relevant failed-session auth results) as loss of usable session; remove protected rendered state, cancel pending reads and clear caches. Reject stale successes/failures from account A after B becomes current and after logout/relogin to the same UID. Protect both TanStack queries and direct service consumers, and avoid late errors expiring a newer account. Signout/failed signout must not leave prior protected content exposed. No account namespace deletion: F5 owns persisted comparison state.

Verification: guarded rootless environment check; frozen npm ci; format:check/lint/typecheck/test:unit/build; Chromium and Firefox full available test:e2e. Instrument deterministic typed services and delayed responses to cover restore without modal flash, anonymous/unverified/resolving zero calls, expiry/revocation/failed refresh, service auth failures, logout, A→B changes, same-UID relogin, abort/cancellation and stale-success rejection. Component/browser probes must verify visible protected sentinels disappear and pending/cache results cannot repopulate UI; use test-only injected composition rather than a shipped auth bypass. Preserve a seeded UID-scoped workspace key through signout/account changes. Record exact commands, SHA and limitations; hand off to independent QA, then hosted quality CI and maintainer merge. Full forms integration/consolidation remains #13/#15, real auth remains B2/I1.

Activity

  1. added
    task
    frontend
    blocked
    on Nov 13, 2026
  2. DavidVFitzGerald commented on Nov 13, 2026

    @DavidVFitzGerald
    OwnerAuthor

    PM: BLOCKED

    Groomed using docs/team/product-manager.md for F2, Phase 1 — frontend with mock services. Documentation review: PASS for scope, required sections, specification coverage and acyclic dependency links; this is not application QA or implementation readiness.

    Blocking predecessor issues: #11, #12. The M1 runtime gate (#2) and merged bootstrap/M2 configuration (#3) also remain required. PM must recheck merged dependencies and current interfaces before changing this to READY.

    Engineer implements one issue, commits regularly and hands the delivered SHA plus exact container checks to independent QA; do not close before QA, review and approved merge. No backend/Firebase/cloud credentials or host installations are required for Phase 1.

  3. DavidVFitzGerald commented on Nov 14, 2026

    @DavidVFitzGerald
    OwnerAuthor

    PM: READY — Phase 1/F2, AC1–5 unchanged. #11/#12 have independent QA PASS and successful required hosted quality; maintainer merged PR #45 (f70420d) and #46 (d05e682), dependencies now closed. Extend merged session store/guard/provider/query helpers per specification §§6.1,6.8,7.4; preserve no-modal-flash restore and workspace storage, harden auth failures/cancel/cache/account isolation with injected component/browser evidence. #13 owns forms/App; #14 owns service-context/queries/provider/controller tests. Coordinate minimal context API if needed and avoid concurrent App edits. Exact bounded scope/checks are appended to body. No ADR/product change required. Handoff to Software Engineer, then independent QA at delivered SHA.

  4. DavidVFitzGerald commented on Nov 14, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Engineering: READY FOR QA

    Branch feat/f2-session-lifecycle (a new branch, because the earlier empty local feat/f2-session-guards worktree was left untouched). Delivered SHA 397fb0d, PR #48.

    Changes: I extended the merged createSessionStore with a local lock/override and invalidate, and hardened guardDataService for 401/403 session loss and stale failures and rejections. I added guardAuthService, which locks before sign-out, and wired it in ApplicationProviders. I removed the App signing-out state that the guard made redundant. The verify panel's sign-out is no longer aborted when it unmounts. Existing useAuthState/services.auth consumers are unchanged.

    Criteria

    • AC1: restoring shows only the loading shell, with no dialog mounted at any point. A unit test checks this with a MutationObserver. A Playwright @smoke test checks it across two reloads with an init-script observer. Implemented.
    • AC2: there are zero protected calls while resolving, anonymous, unverified, errored or locked, and confirmed anonymous state opens the modal. Implemented.
    • AC3: logout, expiry, revocation, failed refresh, verification loss and protected AUTH_REQUIRED/EMAIL_NOT_VERIFIED each remove the sentinel, abort the pending query signal and empty the cache. A late answer cannot repopulate the UI, and slow or failed sign-outs lock first. Implemented.
    • AC4: after switching from A to B, A's cache keys are gone and A's pending query and direct reads are rejected. Same-UID relogin rejects stale reads, and late A failures do not lock B. Implemented.
    • AC5: 15 component tests and 3 browser journeys. A seeded UID-scoped workspace key survives sign-out and switching account, and only the mock session marker is removed. Implemented.

    Commands (project lca-diff-f2-forms, rootless container):

    • ./dev check PASS
    • npm --prefix apps/frontend ci --no-audit --no-fund installs 230 packages with the lockfile unchanged
    • cd apps/frontend && npm run format:check && npm run lint && npm run typecheck && npm run test:unit && npm run build && npm run test:e2e all PASS. Unit: 168/168. E2E: 18/18 across Chromium and Firefox.
    • Mutation check: disabling the invalidate call, the pre-sign-out lock or stale-rejection conversion makes 4 session tests fail.

    Limitations: There is no protected product UI until F3–F5, so the sentinel checks are component-level. Safari was not available. Hosted CI is pending. These mock guards are not real authorization.

    Next: independent QA at 397fb0d.

  5. DavidVFitzGerald commented on Nov 14, 2026

    @DavidVFitzGerald
    OwnerAuthor

    QA: PASS

    Reviewed SHA: 397fb0db71efc4e9bb8da32bbfa9fe234b41de7e (PR #48, branch feat/f2-session-lifecycle), diffed against base 9012a65. I used an isolated detached worktree, and the shared checkout was not touched.
    Mode: Phase 1 mock services only. This evidence does not prove real Firebase/token/backend authorization or data security.
    Environment: a rootless Docker Compose project lca-diff-qa-14. Port 5179 was already bound by another local project (lca-diff-f2-session), so I used FRONTEND_PORT=5183. No other deviation.

    Commands and results

    Command Result
    COMPOSE_PROJECT_NAME=lca-diff-qa-14 FRONTEND_PORT=5183 ./dev up Started
    COMPOSE_PROJECT_NAME=lca-diff-qa-14 FRONTEND_PORT=5183 ./dev check PASS: rootless identity, capabilities, toolchain, frozen uv lock and 8 preflight scenarios
    docker compose -p lca-diff-qa-14 exec -T workspace bash -lc 'npm --prefix apps/frontend ci --no-audit --no-fund' 230 packages added. Host git status --porcelain was clean, so the lockfile is unchanged
    ... bash -lc 'cd apps/frontend; npm run format:check' exit 0
    npm run lint exit 0
    npm run typecheck exit 0
    npm run test:unit 9 files, 168/168 passed
    npm run build exit 0
    npm run test:e2e (Chromium and Firefox) 18/18 passed
    gh pr checks 48 quality pass (2m18s), run 43600520887

    Criteria

    • AC1 PASS. Restore shows only the "Restoring your session…" shell. A unit MutationObserver check confirms no <dialog> is ever mounted. The Playwright @smoke test checks the same thing with an init-script observer across two reloads in both browsers. The modal appears only after a confirmed unauthenticated, unverified or error state.
    • AC2 PASS. guardDataService rejects every non-health operation unless the snapshot is verified, and query enabled is tied to verifiedUid. The test drives resolving, anonymous, unverified, error and locked states and asserts that no data operation is called. E2E monitors assert no fetch/XHR/API requests. Confirmed anonymous state opens "Sign in to LCA diff".
    • AC3 PASS. I reviewed the code and ran the tests and probes:
      • For logout, expiry, revocation, failed refresh and verification loss, the sentinel is removed, the pending AbortSignal is aborted, the cache is empty and a late answer does not repopulate.
      • A protected AUTH_REQUIRED or EMAIL_NOT_VERIFIED result in the current epoch locks the session to error, clears the cache and blocks further reads. A newer adapter state supersedes the lock.
      • Slow and failed sign-outs lock before the adapter answers.
    • AC4 PASS. After A→B, A's cache keys are gone, A's pending query is aborted, and A's direct success, typed failure and thrown failure are all replaced with Authentication context changed. The same happens after logout and relogin as the same UID. Late A AUTH_REQUIRED results do not lock B. TanStack queries and direct services.data consumers are both covered.
    • AC5 PASS.
      • Coverage: 15 component tests in session.test.tsx and 3 Playwright journeys × 2 browsers.
      • The seeded lca-diff:workspace:v1:<uid> key survives sign-out and account switching in both unit and browser tests. Only lca-diff:mock-session:v1 is removed.
      • Tests inject a mode: "test" runtime through ApplicationProviders props. createApplication still accepts only "mock" and throws otherwise, so no auth bypass ships.

    Independent adversarial probes

    I wrote these as a throwaway src/app/qa-probe.test.tsx (9/9 passed) and then deleted it. Each one uses the real createMockAuth with controllable deferred reads:

    1. Two concurrent protected reads returning AUTH_REQUIRED and EMAIL_NOT_VERIFIED: one lock, no throw. The second result is replaced as stale. Signing in again through the dialog form unlocks and shows fresh data.
    2. refreshSession from the locked state: the adapter re-publishes, the session unlocks and fresh reads start.
    3. QueryClient.clear() racing an in-flight refetchQueries() while a direct read locks the session: the refetch signal is aborted and its late success does not repopulate the UI or cache. Further invalidateQueries and refetchQueries calls while locked make zero reads.
    4. Mock sign-out configured to fail (TEMPORARILY_UNAVAILABLE): no protected content, the dialog is visible, the session marker is removed and the workspace key is preserved.
    5. Sign-out from the unverified "Use a different account" panel: the sign-in dialog shows, the marker is removed, zero protected reads happen and there is no alert.
    6. An adapter signOut that throws a non-abort error: content stays removed and direct reads are denied.
    7. A stale direct success after logout without relogin is replaced.

    Mutation check of the shipped tests, reverted afterwards:

    • Removing the pre-sign-out lock makes 1 test fail.
    • Removing the 401/403 invalidate call makes 2 fail.
    • Removing stale-throw conversion makes 1 fail.
    • Removing the epoch check inside invalidate() makes nothing fail. This is not a gap: guardDataService already replaces stale-epoch results before calling invalidate, so that second check is redundant defence.

    Regression and documentation review

    • The [Task] F2: connect mock login, registration, verification and password-reset flows #13 AuthDialog and composition tests are unchanged and pass. The VerifyPanel sign-out no longer forwards an unmount-abort signal. This is correct because the guard locks first, and probe 5 confirms the flow. The App's inline "Sign out failed" alert was replaced by the locked error modal notice, which is consistent with spec §6.1 ("401/403 returns the user to the modal without exposing previously rendered licensed data").
    • The behaviour matches spec §§6.1, 6.8 (sign-out does not delete account-scoped state, caches are cleared) and 7.4, and PRD §3. No PRD or spec deviation was found, so no ADR is required. The README [Task] F2: guard protected queries through session restoration and account changes #14 section and docs/engineering/f2-session-verification.md are accurate. No historical folders were used.

    Non-blocking observations (no defect filed)

    1. If an adapter's signOut fails without emitting a new state while the user is unverified, the lock override shows the plain sign-in form with no error, and the adapter's unverified session marker remains. A reload restores the verify panel. This exposes no protected data, and the shipped mock always emits unauthenticated before it awaits, so the case is unreachable in Phase 1. Phase 2 should decide the UX when real sign-out fails.
    2. Any adapter re-emission of the same verified state clears a local 401/403 lock. This is by design, but in Phase 2 a token refresh against a persistent server-side 403 could cycle lock, unlock and 403 once per emission. Track it for B2/I1.
    3. There is no protected product UI until F3–F5, so sentinel removal is proven only at component level. Safari was not tested.

    Next action: coordinator and maintainer review and merge PR #48. No engineering rework is required.

  6. DavidVFitzGerald commented on Nov 14, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator: closing. Independent QA PASS at 397fb0d, required hosted quality SUCCESS, maintainer merge of PR #48. Phase 2 (B2/I1) notes from QA: decide signout-failure UX for unverified sessions when the adapter emits no new state; avoid lock/unlock cycling when a real adapter re-emits the same verified state against a persistent server 401/403.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedfrontendtask

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions