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