We recently upgraded from Angular 13.3 to Angular 14. Since then we're having issues when the user refreshes a page.
We have an HttpInterceptor which checks that we still have the user information.
It looks like the this.globalObservalStateService.getUser() no longer returns an observable after a refresh.
I've added several console.log statements. I also added a getUser().subscribe to see if maybe that will still return a value. And I added a 'showuser' as the first statement in the pipe which should execute for everything returned by the pipe. The pipe always returns only one observable.
The console.log in getUser always shows a value but all the other console.log indicate that the user object/observable is empty/undefined.
Has anyone had a similar issue after upgrading to Angular 14?
globalObservalStateService:
private user = new BehaviorSubject<User>(null);
getUser(): Observable<User> {
console.log('getUser');
console.log(this.user);
return this.user.asObservable();
}
Interceptor service:
intercept(req: HttpRequest<any>, next: HttpHandler): any {
console.log('intercept');
// added to investigate the issue
this.globalObservalStateService.getUser()
.subscribe(userResult => {
if (userResult) {
console.log('subscribe user is filled');
} else {
console.log('subscribe !user');
}
});
return this.globalObservalStateService.getUser().pipe(
// map added to investigate the issue
map((x) => (x = this.showuser(x))),
take(1),
exhaustMap((user: User) => {
if (!user) {
console.log('map !user');
} else {
console.log('map user filled');
}
etc.
}
// added to investigate the issue
showuser(user: User) : User {
if (!user) {
console.log ('showuser: !user');
} else {
console.log('showuser user is filled');
}
return user;
}