Delay checkAuthStatus execution on auth service initialization and add logging for username retrieval and errors.

This commit is contained in:
akastijn 2025-11-23 04:46:58 +01:00
parent b15386d157
commit 9ab0a130ed

View File

@ -1,6 +1,6 @@
import {Injectable, signal} from '@angular/core';
import {LoginService} from '@api';
import {Observable, throwError} from 'rxjs';
import {Observable, throwError, timer} from 'rxjs';
import {catchError, tap} from 'rxjs/operators';
import {MatSnackBar} from '@angular/material/snack-bar';
import {JwtHelperService} from '@auth0/angular-jwt';
@ -23,7 +23,9 @@ export class AuthService {
private snackBar: MatSnackBar
) {
// Check if user is already logged in on service initialization
this.checkAuthStatus();
timer(1000).subscribe(() => {
this.checkAuthStatus();
});
}
/**
@ -46,13 +48,16 @@ export class AuthService {
private reloadUsername() {
if (window.location.hostname === 'localhost') {
console.log("Reloading username for localhost");
this._username.set('developer');
}
this.loginService.getUsername().subscribe({
next: (username) => {
console.log("Username retrieved: " + username.username);
this._username.set(username.username);
},
error: (error) => {
console.error("Error retrieving username:", error);
return throwError(() => error);
}
});