Why my alert is being thrown before I can print console.log("outside the .then" + this.result);
?
The result is true, my this.result = Admin_product
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
this.oktaAuthService.getUser().then(
(res) => {
this.result = res.groups.find((group) => group === 'Admin_product');
console.log("inside the .then" + (this.result))
}
)
if (this.result === 'Admin_product') {
console.log("outside the .then" + this.result);
return true;
} else {
alert('User is not authorized to perform this operation');
return false;
}
}