Fix Supabase proxy to properly handle connection failures

cgen-4d110997bc7a4d9bbd0b8c087b10faae
This commit is contained in:
Builder.io 2025-08-17 00:15:11 +00:00
parent f6896a7d5d
commit 3d50af82cd

View file

@ -48,18 +48,26 @@ export const supabase = new Proxy(supabaseClient || {}, {
if (prop === 'auth') {
return {
signInWithPassword: async (credentials: any) => {
if (isSupabaseConfigured && target.auth) {
if (isSupabaseConfigured && target && target.auth) {
try {
return await target.auth.signInWithPassword(credentials);
console.log("Attempting Supabase authentication...");
const result = await target.auth.signInWithPassword(credentials);
console.log("✅ Supabase authentication successful");
return result;
} catch (error: any) {
if (error.message?.includes('Failed to fetch')) {
console.log("🔄 Supabase failed, using mock auth");
console.warn("⚠️ Supabase authentication failed:", error.message);
if (error.message?.includes('Failed to fetch') ||
error.name === 'AuthRetryableFetchError' ||
error.message?.includes('fetch')) {
console.log("🔄 Falling back to mock authentication");
return await mockAuth.signInWithPassword(credentials.email, credentials.password);
}
throw error;
}
} else {
console.log("🔄 Using mock authentication (Supabase not configured)");
return await mockAuth.signInWithPassword(credentials.email, credentials.password);
}
return await mockAuth.signInWithPassword(credentials.email, credentials.password);
},
signOut: async () => {
if (isSupabaseConfigured && target.auth) {