Fix Supabase proxy to properly handle connection failures
cgen-4d110997bc7a4d9bbd0b8c087b10faae
This commit is contained in:
parent
f6896a7d5d
commit
3d50af82cd
1 changed files with 13 additions and 5 deletions
|
|
@ -48,18 +48,26 @@ export const supabase = new Proxy(supabaseClient || {}, {
|
||||||
if (prop === 'auth') {
|
if (prop === 'auth') {
|
||||||
return {
|
return {
|
||||||
signInWithPassword: async (credentials: any) => {
|
signInWithPassword: async (credentials: any) => {
|
||||||
if (isSupabaseConfigured && target.auth) {
|
if (isSupabaseConfigured && target && target.auth) {
|
||||||
try {
|
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) {
|
} catch (error: any) {
|
||||||
if (error.message?.includes('Failed to fetch')) {
|
console.warn("⚠️ Supabase authentication failed:", error.message);
|
||||||
console.log("🔄 Supabase failed, using mock auth");
|
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);
|
return await mockAuth.signInWithPassword(credentials.email, credentials.password);
|
||||||
}
|
}
|
||||||
throw error;
|
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 () => {
|
signOut: async () => {
|
||||||
if (isSupabaseConfigured && target.auth) {
|
if (isSupabaseConfigured && target.auth) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue