I have an Angular 7 app in which I have a post call and on the basis of that post call response I want to make guard active/inactive. I have my route guard like this
canActivate = (_router: ActivatedRouteSnapshot): boolean => {
console.log('in link expiry guard')
let userEmail = _router.paramMap.get('email');
let isAllow;
console.log('params : ', userEmail)
userEmail = this._utilityService.decryptMsgByCryptoJs(userEmail);
console.log('user email : ', userEmail)
this._dataService.post(this._const.userResetPasswordLinkExpiry, { email: userEmail }).subscribe(resp => {
console.log('verify response : ',resp)
if (resp.success) {
console.log('in success')
isAllow = true;
} else {
isAllow = false;
}
})
console.log('allow flag : ',isAllow)
if (isAllow) {
console.log('in allow')
return true;
} else {
console.log('in not allow')
this._utilityService.navigate('/login');
this._dataService.exhangeResetPasswordObsMsg({ event: 'linkExpired' });
return false;
}
}
But problem is that while my http
post
call is being in progress so my guard executes completely and returning false and after that response is coming from post call. How can I manage this scenario so I will make route true or false based on http
post
call response.