const KEY = "magicbell-redirect"; const TTL_MS = 60_000; // 10 minutes type RedirectEntry = { channel: string; id: string; ts: number; }; export const redirectStorage = { set(channel: string, id: string) { localStorage.setItem(KEY, JSON.stringify({ channel, id, ts: Date.now() })); }, get(): RedirectEntry | null { if (typeof localStorage === "undefined") return null; const raw = localStorage.getItem(KEY); if (!raw) return null; try { const entry = JSON.parse(raw) as RedirectEntry; if (Date.now() - entry.ts > TTL_MS) { redirectStorage.clear(); return null; } return entry; } catch { redirectStorage.clear(); return null; } }, matches(channel: string, id: string): boolean { const entry = redirectStorage.get(); return !!entry && entry.channel === channel && entry.id === id; }, clear() { if (typeof localStorage === "undefined") return; localStorage.removeItem(KEY); } }