Fix Supabase configuration and add proper connection testing
cgen-273c48e01e314dc392022b241ace8cee
This commit is contained in:
parent
478dc8836b
commit
117850501b
1 changed files with 38 additions and 32 deletions
|
|
@ -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<Database>(demoUrl, demoKey);
|
||||
} else {
|
||||
console.log("Supabase configured with URL:", supabaseUrl);
|
||||
export const isSupabaseConfigured = true;
|
||||
|
||||
export const supabase = createClient<Database>(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<Database>(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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue