fix(mana/web): sprint 2 — auth-aware data layer + guest migration

- Single source of truth for the active user via data/current-user.ts;
  layout pushes authStore.user.id into it on every auth state change.
- Dexie creating-hook auto-stamps userId from getEffectiveUserId(); the
  updating-hook strips userId from modifications so records are
  effectively user-immutable after creation.
- BaseRecord gains an optional userId so module types inherit it without
  per-module declarations. All hardcoded 'guest'/'local' fallbacks in
  module type-converters and session timer stores are deleted; the dead
  userId field is removed from the public view types where it was
  unused (Task, Conversation, Template, Deck, Plant, Contact, etc.).
- New guest-migration.ts: on first authenticated session, walks every
  sync-tracked table, deletes guest-owned records and re-adds them so
  the creating-hook re-stamps with the real user id and produces fresh
  insert pending-changes with the full payload. Stale guest pending-
  changes are cleared up-front.
- Drive-by: root onMount now returns its cleanup synchronously; the
  previous async form silently dropped the cleanup callback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-07 13:07:12 +02:00
parent 0909538827
commit 28942abede
24 changed files with 182 additions and 47 deletions

View file

@ -5,6 +5,11 @@
/** Base record that all local-store entities must extend. */
export interface BaseRecord {
id: string;
/**
* Owner of this record. Auto-stamped by the Dexie creating-hook from the
* active session user; module stores must never set this themselves.
*/
userId?: string;
createdAt?: string;
updatedAt?: string;
deletedAt?: string | null;