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