From f3dd6b3dceb60757480a67445cae7a90e1ed5c9a Mon Sep 17 00:00:00 2001 From: Mahi Date: Mon, 9 Feb 2026 15:18:52 -0400 Subject: [PATCH] fix: Add delay to login guard and more debug logging --- frontend/src/app/core/services/auth.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/core/services/auth.service.ts b/frontend/src/app/core/services/auth.service.ts index ba270f2..4f6898d 100644 --- a/frontend/src/app/core/services/auth.service.ts +++ b/frontend/src/app/core/services/auth.service.ts @@ -93,6 +93,7 @@ export class AuthService implements OnDestroy { private loadStoredUser(): void { const token = this.storage.getToken(); const user = this.storage.getUser(); + console.log('[AUTH DEBUG] loadStoredUser - token:', token ? 'EXISTS' : 'NULL', 'user:', user ? 'EXISTS' : 'NULL'); // Only restore state if we have both valid token AND user if (token && user) { @@ -125,6 +126,7 @@ export class AuthService implements OnDestroy { private setupStorageListener(): void { if (typeof window !== 'undefined') { this.storageListener = (event: StorageEvent) => { + console.log('[AUTH DEBUG] Storage event received, key:', event.key, 'isLoginInProgress:', this.isLoginInProgress); // Skip if login is in progress to avoid race conditions if (this.isLoginInProgress) { console.log('[AUTH DEBUG] Skipping storage event during login'); @@ -276,7 +278,10 @@ export class AuthService implements OnDestroy { this.storage.setUser(user); this.updateAuthState(user, true); } finally { - this.isLoginInProgress = false; + // Delay clearing the login flag to allow async storage events to be ignored + setTimeout(() => { + this.isLoginInProgress = false; + }, 500); this._isLoading.set(false); } }