I have a service that has a method for checking if the user is valid or not.
auth.service:
checkUserValidity(): boolean {
this.isValidUser().subscribe(response => {
console.log('user valid response');
console.log('response');
return true;
}, (error: AppError) => {
console.log('error in checkUserValidaty');
console.log(error);
});
return false;
}
isValidUser(): Observable<any> {
const requestUrl = environment.gatewayUrl + environment.authorizationService + environment.userServiceEndPoint;
return this.httpClient.get(requestUrl).catch(this.errorService.handleError);
}
And then there is another class, which is calling this service:
if (this.authService.isLoggedIn() && this.authService.checkUserValidity()) {
return true;
}
The problem is that checkUserValidity():
always returns false, because it doesn't work in an async way. I need to be able to determine if the observable completed without errors, or not and for the checkUserValidity()
to complete only after it has completing evaluating the Observable
result.