fix: Add delay to login guard and more debug logging
This commit is contained in:
@@ -93,6 +93,7 @@ export class AuthService implements OnDestroy {
|
||||
private loadStoredUser(): void {
|
||||
const token = this.storage.getToken();
|
||||
const user = this.storage.getUser<CurrentUserDto>();
|
||||
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 {
|
||||
// Delay clearing the login flag to allow async storage events to be ignored
|
||||
setTimeout(() => {
|
||||
this.isLoginInProgress = false;
|
||||
}, 500);
|
||||
this._isLoading.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user