In my Angular 7 application, I have implemented a route guard that is dependent on the response of a post call. The guard is structured 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;
}
}
The issue arises when the HTTP post call is still in progress and the guard executes completely, returning false. This leads to complications as the response from the post call arrives later. How can I handle this situation effectively so that the route can be determined based on the post call response?