Improve mock auth session management
cgen-c34330c73eeb4aa8873011c6f6e86489
This commit is contained in:
parent
d524f128f1
commit
cd3ebd8852
1 changed files with 19 additions and 2 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue