From a4da9b5613ed8d84851cc54aa00465bb06a9c428 Mon Sep 17 00:00:00 2001 From: Mahi Date: Mon, 9 Feb 2026 15:28:22 -0400 Subject: [PATCH] fix: Don't clear auth when token exists but user is missing (race condition) --- frontend/src/app/core/services/auth.service.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/core/services/auth.service.ts b/frontend/src/app/core/services/auth.service.ts index 4f6898d..cd75a5e 100644 --- a/frontend/src/app/core/services/auth.service.ts +++ b/frontend/src/app/core/services/auth.service.ts @@ -114,7 +114,13 @@ export class AuthService implements OnDestroy { } } else if (token || user) { // Inconsistent state - clear everything - console.warn('Inconsistent auth state detected, clearing...'); + console.warn('Inconsistent auth state detected, clearing... token:', !!token, 'user:', !!user); + // Don't clear if we have a valid token - just log and continue + // This prevents race conditions from clearing valid auth state + if (token) { + console.warn('Token exists but user missing - NOT clearing (likely race condition)'); + return; + } this.clearAuthState(); } } @@ -281,7 +287,8 @@ export class AuthService implements OnDestroy { // Delay clearing the login flag to allow async storage events to be ignored setTimeout(() => { this.isLoginInProgress = false; - }, 500); + console.log('[AUTH DEBUG] Login guard cleared after delay'); + }, 2000); this._isLoading.set(false); } }