Improve mock auth session management

cgen-c34330c73eeb4aa8873011c6f6e86489
This commit is contained in:
Builder.io 2025-08-17 00:15:45 +00:00
parent d524f128f1
commit cd3ebd8852

View file

@ -142,20 +142,37 @@ class MockAuthService {
} }
onAuthStateChange(callback: (event: string, session: MockSession | null) => void) { onAuthStateChange(callback: (event: string, session: MockSession | null) => void) {
// Store callback for later use
this.authCallback = callback;
// Immediately call with current state // Immediately call with current state
setTimeout(() => { setTimeout(() => {
callback(this.currentSession ? 'SIGNED_IN' : 'SIGNED_OUT', this.currentSession); if (this.currentSession) {
callback('SIGNED_IN', this.currentSession);
} else {
callback('SIGNED_OUT', null);
}
}, 100); }, 100);
// Return unsubscribe function // Return unsubscribe function
return { return {
data: { data: {
subscription: { 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(); export const mockAuth = new MockAuthService();