From cd3ebd885279b8231b6dab00840424e9ff00ca2a Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 17 Aug 2025 00:15:45 +0000 Subject: [PATCH] Improve mock auth session management cgen-c34330c73eeb4aa8873011c6f6e86489 --- client/lib/mock-auth.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/client/lib/mock-auth.ts b/client/lib/mock-auth.ts index 1bdc468f..dde44c6b 100644 --- a/client/lib/mock-auth.ts +++ b/client/lib/mock-auth.ts @@ -142,20 +142,37 @@ class MockAuthService { } onAuthStateChange(callback: (event: string, session: MockSession | null) => void) { + // Store callback for later use + this.authCallback = callback; + // Immediately call with current state setTimeout(() => { - callback(this.currentSession ? 'SIGNED_IN' : 'SIGNED_OUT', this.currentSession); + if (this.currentSession) { + callback('SIGNED_IN', this.currentSession); + } else { + callback('SIGNED_OUT', null); + } }, 100); // Return unsubscribe function return { data: { subscription: { - unsubscribe: () => {} + unsubscribe: () => { + this.authCallback = null; + } } } }; } + + private authCallback: ((event: string, session: MockSession | null) => void) | null = null; + + private notifyAuthChange(event: string) { + if (this.authCallback) { + this.authCallback(event, this.currentSession); + } + } } export const mockAuth = new MockAuthService();