import {createSessionCache, type SessionCache} from '$lib/sessionCache'; /** * Persists the source ('old') and destination ('new') login sessions of an in-progress * migration in localStorage so a page refresh can offer to resume it instead of forcing the * user to re-enter credentials and re-trigger 2FA. All persistence policy lives in the generic * `sessionCache` factory; the `@pds-moover/moover` package only exposes generic hooks * (onSessionUpdate / restoreSessions). * * Security note: this stores access + refresh JWTs in localStorage. Acceptable for this SPA, * mitigated by clearing on completion / start-over and by PasswordSession.resume() invalidating * dead sessions. */ const STORAGE_KEY = 'pdsmoover:migration-sessions:v1'; export type MigrationSessionCache = SessionCache<'old' | 'new'>; // Resume is only offered when BOTH sides are present (an old-side-only entry means no destination // account was ever logged into — nothing to resume), so an orphaned single side is cleared. const cache = createSessionCache<'old' | 'new'>(STORAGE_KEY, ['old', 'new']); /** * Persist (data) or drop (null) one side of the migration. When both sides end up gone the * whole key is removed so we never leave an orphaned entry behind. */ export const saveSide = cache.saveSide; /** * Read the cached sessions. Resume is only offered when BOTH sides are present (an old-side-only * entry means no destination account was ever logged into — nothing to resume), so an orphaned * single side is cleared and null is returned. */ export const load = cache.load; /** Remove the whole cache entry (completion / start-over / expired sessions). */ export const clear = cache.clear;