fix: Don't clear auth when token exists but user is missing (race condition)

This commit is contained in:
Mahi
2026-02-09 15:28:22 -04:00
parent f851e31f30
commit a4da9b5613

View File

@@ -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);
}
}