From 18b2033fc053a13f50bdd6a835f7c1f27bf898cb Mon Sep 17 00:00:00 2001 From: coder-soft Date: Sun, 26 Jul 2026 12:34:55 +0500 Subject: [PATCH 1/2] fix: prevent wisp Not initialized errors from bindSupabase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove bindSupabase() call — its onAuthStateChange callback lacks try-catch and throws when wisp init timing is delayed - Restore manual tryIdentify/tryReset with try-catch guards in AuthProvider, matching the original safe pattern - Keep metadata enrichment: track session_identify event with email/name/provider on sign-in and existing session recovery --- src/main.tsx | 3 --- src/providers/AuthProvider.tsx | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index 9543fb3..cee7de1 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -9,15 +9,12 @@ import '@fontsource/geist-mono'; import '@fontsource/jetbrains-mono'; import wisp, { init } from "@renderdragonorg/wisp"; -import { bindSupabase } from "@renderdragonorg/wisp/supabase"; -import { supabase } from "@/integrations/supabase/client"; const convexUrl = import.meta.env.VITE_CONVEX_URL; const wispSecret = import.meta.env.VITE_WISP_SECRET; if (convexUrl) { init({ convexUrl, wispSecret: wispSecret || undefined }); - bindSupabase(supabase); } // expose for console debugging diff --git a/src/providers/AuthProvider.tsx b/src/providers/AuthProvider.tsx index ed6240f..bd007ac 100644 --- a/src/providers/AuthProvider.tsx +++ b/src/providers/AuthProvider.tsx @@ -2,6 +2,29 @@ import { useState, useEffect } from "react"; import { User, Session } from "@supabase/supabase-js"; import { supabase } from "@/integrations/supabase/client"; import { AuthContext, AuthResult } from "@/providers/AuthContext"; +import wisp from "@renderdragonorg/wisp"; + +function tryIdentify(userId: string) { + try { wisp.identify(userId); } catch { /* wisp not initialized */ } +} +function tryReset() { + try { wisp.reset(); } catch { /* wisp not initialized */ } +} +function tryTrackIdentify(session: Session | null) { + const user = session?.user; + if (!user?.id) return; + try { + const meta = user.user_metadata as Record || {}; + const identities = (user.identities ?? []) as Array<{ provider?: string | null }>; + const primaryIdentity = identities.find((i) => i.provider === (user.app_metadata?.provider as string)) ?? identities[0]; + wisp.track("session_identify", { + email: user.email, + name: meta.full_name as string | undefined, + provider: primaryIdentity?.provider ?? user.app_metadata?.provider ?? "email", + }); + } catch { /* wisp not initialized */ } +} + export const AuthProvider = ({ children }: { children: React.ReactNode }) => { const [user, setUser] = useState(null); const [session, setSession] = useState(null); @@ -14,12 +37,23 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { setSession(session); setUser(session?.user ?? null); setLoading(false); + + if (event === "SIGNED_IN" && session?.user.id) { + tryIdentify(session.user.id); + tryTrackIdentify(session); + } else if (event === "SIGNED_OUT") { + tryReset(); + } }); supabase.auth.getSession().then(({ data: { session } }) => { setSession(session); setUser(session?.user ?? null); setLoading(false); + if (session?.user.id) { + tryIdentify(session.user.id); + tryTrackIdentify(session); + } }); return () => subscription.unsubscribe(); From 2c59e756e3e66ea41f68c906482bb12a164b389e Mon Sep 17 00:00:00 2001 From: coder-soft Date: Sun, 26 Jul 2026 12:43:22 +0500 Subject: [PATCH 2/2] fix: retry identify and session_identify if wisp not yet initialized - When identify/track fails because wisp isn't ready, retry up to 3 times with 500ms delay via setTimeout instead of silently dropping --- src/providers/AuthProvider.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/providers/AuthProvider.tsx b/src/providers/AuthProvider.tsx index bd007ac..84bde06 100644 --- a/src/providers/AuthProvider.tsx +++ b/src/providers/AuthProvider.tsx @@ -4,13 +4,16 @@ import { supabase } from "@/integrations/supabase/client"; import { AuthContext, AuthResult } from "@/providers/AuthContext"; import wisp from "@renderdragonorg/wisp"; -function tryIdentify(userId: string) { - try { wisp.identify(userId); } catch { /* wisp not initialized */ } +function tryIdentify(userId: string, retries = 3) { + try { wisp.identify(userId); } + catch { + if (retries > 0) setTimeout(() => tryIdentify(userId, retries - 1), 500); + } } function tryReset() { try { wisp.reset(); } catch { /* wisp not initialized */ } } -function tryTrackIdentify(session: Session | null) { +function tryTrackIdentify(session: Session | null, retries = 3) { const user = session?.user; if (!user?.id) return; try { @@ -22,7 +25,9 @@ function tryTrackIdentify(session: Session | null) { name: meta.full_name as string | undefined, provider: primaryIdentity?.provider ?? user.app_metadata?.provider ?? "email", }); - } catch { /* wisp not initialized */ } + } catch { + if (retries > 0) setTimeout(() => tryTrackIdentify(session, retries - 1), 500); + } } export const AuthProvider = ({ children }: { children: React.ReactNode }) => {