From 803a6ab76624af5fb1843f2db6dead0b0a7d350a Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 26 Aug 2026 13:15:22 +0000 Subject: [PATCH 1/2] feat: add Jam SDK for bug report recording and debugging Installs the Jam recorder/capture scripts on the connected debate.pi-stack.org domain and tags bug reports with the signed-in Supabase user id via jam.metadata(), so reports can be correlated back to accounts. --- index.html | 3 +++ package-lock.json | 7 +++++++ package.json | 1 + src/lib/jam-metadata.ts | 9 +++++++++ src/lib/supabase/AuthProvider.tsx | 4 ++++ 5 files changed, 24 insertions(+) create mode 100644 src/lib/jam-metadata.ts diff --git a/index.html b/index.html index 58472c473..f52ab99ad 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,9 @@ + + + DebateLab by Programcode | AI Debate Prep, Cases & Rebuttals diff --git a/package-lock.json b/package-lock.json index 7fe3c2883..8023db8b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "@capacitor/keyboard": "^8.0.3", "@capacitor/status-bar": "^8.0.2", "@hookform/resolvers": "^3.10.0", + "@jam.dev/sdk": "^1.0.1", "@radix-ui/react-accordion": "^1.2.11", "@radix-ui/react-alert-dialog": "^1.1.14", "@radix-ui/react-aspect-ratio": "^1.1.7", @@ -1254,6 +1255,12 @@ "node": ">=18.0.0" } }, + "node_modules/@jam.dev/sdk": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@jam.dev/sdk/-/sdk-1.0.1.tgz", + "integrity": "sha512-M7KZt079P76BnevBq/z+OaFZGPfA8KVbDSmc9+ARJhPz1t9IeTjrM0cLzbf+07H9IcVizovO65bhdMUWm9EFRQ==", + "license": "Apache-2.0" + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", diff --git a/package.json b/package.json index c41bb817e..3572f0058 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@capacitor/keyboard": "^8.0.3", "@capacitor/status-bar": "^8.0.2", "@hookform/resolvers": "^3.10.0", + "@jam.dev/sdk": "^1.0.1", "@radix-ui/react-accordion": "^1.2.11", "@radix-ui/react-alert-dialog": "^1.1.14", "@radix-ui/react-aspect-ratio": "^1.1.7", diff --git a/src/lib/jam-metadata.ts b/src/lib/jam-metadata.ts new file mode 100644 index 000000000..26d524b7c --- /dev/null +++ b/src/lib/jam-metadata.ts @@ -0,0 +1,9 @@ +import { jam } from "@jam.dev/sdk"; + +let currentUserId: string | undefined; + +jam.metadata(() => ({ userId: currentUserId })); + +export function setJamUserId(userId: string | undefined): void { + currentUserId = userId; +} diff --git a/src/lib/supabase/AuthProvider.tsx b/src/lib/supabase/AuthProvider.tsx index 59c888327..3f3579e93 100644 --- a/src/lib/supabase/AuthProvider.tsx +++ b/src/lib/supabase/AuthProvider.tsx @@ -5,6 +5,7 @@ import { supabase } from './client'; import { useSessionStore } from '@/lib/stores/session-store'; import { useSettingsStore } from '@/lib/stores/settings-store'; import { getOAuthRedirectUrl, openExternalUrl } from '@/lib/native'; +import { setJamUserId } from '@/lib/jam-metadata'; interface AuthContextValue { session: Session | null; @@ -98,6 +99,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { if (oauthSession) { setSession(oauthSession); currentUserIdRef.current = oauthSession.user?.id; + setJamUserId(oauthSession.user?.id); setLoading(false); hydrateStores(oauthSession.user?.id); return; @@ -117,6 +119,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { if (error) console.warn('[Auth] getSession error:', error.message); setSession(data.session ?? null); currentUserIdRef.current = data.session?.user?.id; + setJamUserId(data.session?.user?.id); if (data.session) { hydrateStores(data.session.user?.id); } @@ -137,6 +140,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { const prevUserId = currentUserIdRef.current; const nextUserId = newSession?.user?.id; currentUserIdRef.current = nextUserId; + setJamUserId(nextUserId); setSession(newSession); setLoading(false); From 3adaec2359e91c92178f3059d453290258ad6226 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 26 Aug 2026 13:57:36 +0000 Subject: [PATCH 2/2] fix: clear Jam user id when auth init fails The init() catch path reset the session to null but left the Jam metadata user id (and the ref backing it) pointing at whatever user was last known, so a failed init after a real sign-in could tag subsequent Jam bug reports with a stale/signed-out user id. --- src/lib/supabase/AuthProvider.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/supabase/AuthProvider.tsx b/src/lib/supabase/AuthProvider.tsx index 3f3579e93..24773791b 100644 --- a/src/lib/supabase/AuthProvider.tsx +++ b/src/lib/supabase/AuthProvider.tsx @@ -127,6 +127,8 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { console.warn('[Auth] init failed:', err); if (!mounted) return; setSession(null); + currentUserIdRef.current = undefined; + setJamUserId(undefined); } finally { if (mounted) setLoading(false); }