Refactor reloadUsername in auth.service to remove debug logs, simplify subscription handling, and add null check before invocation.

This commit is contained in:
akastijn 2025-08-05 23:29:37 +02:00
parent 4222df87a3
commit 238c5d9644

View File

@ -47,17 +47,14 @@ export class AuthService {
} }
private reloadUsername() { private reloadUsername() {
console.log("Reloading username"); this.loginService.getUsername().subscribe({
this.loginService.getUsername().pipe( next: (username) => {
tap(username => {
console.log("Username: ", username);
this._username.set(username.username); this._username.set(username.username);
}), },
catchError(error => { error: (error) => {
console.log("Error: ", error);
return throwError(() => error); return throwError(() => error);
}) }
) });
} }
/** /**
@ -90,7 +87,9 @@ export class AuthService {
console.log("User claims: ", claims); console.log("User claims: ", claims);
this.userClaimsSubject.next(claims); this.userClaimsSubject.next(claims);
this.isAuthenticatedSubject.next(true); this.isAuthenticatedSubject.next(true);
if (this.username() == null) {
this.reloadUsername(); this.reloadUsername();
}
return true; return true;
} catch (e) { } catch (e) {
this.logout(); this.logout();