Fix auth state updates when Supabase auth falls back to mock by subscribing to both real and mock auth state changes
cgen-8e8e553dd55a470b8f18a9db949b0a5b
This commit is contained in:
parent
d7dc308cb6
commit
86db6bac9e
1 changed files with 21 additions and 3 deletions
|
|
@ -132,14 +132,32 @@ export const supabase = new Proxy(supabaseClient || {}, {
|
|||
return await mockAuth.getSession();
|
||||
},
|
||||
onAuthStateChange: (callback: any) => {
|
||||
let realSub: any = null;
|
||||
if (isSupabaseConfigured && target && target.auth) {
|
||||
try {
|
||||
return target.auth.onAuthStateChange(callback);
|
||||
realSub = target.auth.onAuthStateChange(callback);
|
||||
} catch (error) {
|
||||
console.warn("Supabase onAuthStateChange failed, using mock");
|
||||
console.warn("Supabase onAuthStateChange failed, will use mock too");
|
||||
}
|
||||
}
|
||||
return mockAuth.onAuthStateChange(callback);
|
||||
// Always subscribe to mock as a safety net in case we fall back during auth
|
||||
const mockSub = mockAuth.onAuthStateChange(callback);
|
||||
|
||||
// Return a combined unsubscribe that cleans up both
|
||||
return {
|
||||
data: {
|
||||
subscription: {
|
||||
unsubscribe: () => {
|
||||
try {
|
||||
realSub?.data?.subscription?.unsubscribe?.();
|
||||
} catch {}
|
||||
try {
|
||||
mockSub?.data?.subscription?.unsubscribe?.();
|
||||
} catch {}
|
||||
},
|
||||
},
|
||||
},
|
||||
} as any;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue