Within my local or session storage, there exists a JWT token containing the userId information.
When a user refreshes the page on a route such as
test.com/route2
the app.components.ts initiates an http request to fetch the roles.
constructor(
private userService: UserService
)
{
this.userService.getUser(this.subId()).toPromise().then((data)=>{ this.setLoggedUser(data);
});
}
The issue arises in the ngInit event of Route2, which is handled by route2.component.ts. I am sending an http request to retrieve customer data, but it gets executed before the LoggedUser is set, resulting in a null error.
this.groupService.getAllCustomersOfGroup(this.getLoggedUser().Group.Id).subscribe(
data => this.customers = data,
err => this.error(err),
() => { this.loadingHideSucces(); }
);