From 117850501bb8515b1189931acf6da7abc7eec7f4 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 17 Aug 2025 00:04:37 +0000 Subject: [PATCH] Fix Supabase configuration and add proper connection testing cgen-273c48e01e314dc392022b241ace8cee --- client/lib/supabase.ts | 70 +++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/client/lib/supabase.ts b/client/lib/supabase.ts index fe772c81..db7134c0 100644 --- a/client/lib/supabase.ts +++ b/client/lib/supabase.ts @@ -4,41 +4,47 @@ import type { Database } from "./database.types"; const supabaseUrl = import.meta.env.VITE_SUPABASE_URL; const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY; -// Validate required environment variables +console.log("Supabase Config:", { + hasUrl: !!supabaseUrl, + hasKey: !!supabaseAnonKey, + url: supabaseUrl?.substring(0, 30) + "..." +}); + +// For development, let's use a working demo setup if the current one fails +let finalUrl = supabaseUrl; +let finalKey = supabaseAnonKey; + +// Check if we have the environment variables if (!supabaseUrl || !supabaseAnonKey) { - console.error("Missing Supabase environment variables. Using demo mode."); - // Use demo values for development - const demoUrl = "https://demo.supabase.co"; - const demoKey = "demo-key"; - - export const isSupabaseConfigured = false; - export const supabase = createClient(demoUrl, demoKey); -} else { - console.log("Supabase configured with URL:", supabaseUrl); - export const isSupabaseConfigured = true; - - export const supabase = createClient(supabaseUrl, supabaseAnonKey, { - auth: { - autoRefreshToken: true, - persistSession: true, - detectSessionInUrl: true, - }, - }); - - // Test the connection - supabase.from('user_profiles').select('count', { count: 'exact', head: true }) - .then(({ error }) => { - if (error) { - console.error("Supabase connection test failed:", error); - } else { - console.log("Supabase connection test successful"); - } - }) - .catch((err) => { - console.error("Supabase connection error:", err); - }); + console.warn("Missing Supabase environment variables"); + finalUrl = "https://demo.supabase.co"; + finalKey = "demo-key"; } +export const isSupabaseConfigured = !!(supabaseUrl && supabaseAnonKey); + +export const supabase = createClient(finalUrl, finalKey, { + auth: { + autoRefreshToken: true, + persistSession: true, + detectSessionInUrl: true, + }, +}); + +// Test connection in a non-blocking way +setTimeout(async () => { + try { + const { error } = await supabase.from('user_profiles').select('count', { count: 'exact', head: true }); + if (error) { + console.error("Supabase connection test failed:", error.message); + } else { + console.log("✅ Supabase connection successful"); + } + } catch (err: any) { + console.error("❌ Supabase connection error:", err.message); + } +}, 1000); + // Auth helpers export const auth = supabase.auth;