Canactivate is returning false always coming from API condition check angular

  angular, canactivate

I have used canActivate to protect a page but it always returning false because of that I can not access the protected router. I tried many ways, but was not successful to fix the issue. I am new to angular and i am stuck in validating the condition if (data.hasPermission == true).

can any one please help me.


//Checking user access
    getUserAccess(name: string): Observable<any> {

        return this.http.get(`api/${name}/useraccess`).pipe(
                (response: any) => {
                    return response;

checkUserPermission() {

        this.getUserAccess( => {
this.hasaccess = false;
           if (data.hasPermission == true) {
                this.hasaccess = true;
            } else {
                 this.hasaccess = false;
         return this.hasaccess

isUserHasAccess(): boolean {
 return this.hasaccess


canActivate(route: ActivatedRouteSnapshot,
        state: RouterStateSnapshot): boolean {
if (this.authService.isUserHasAccess()) {

            return true;
        } else {
            return false;

json data from API


Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.