The question about Angular CanActivate

export class AuthGuard implements CanActivate {

    constructor(private PassportService: PassportService, private CookieService: CookieService, private router: Router) {

    }

    canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        console.log("yoyoyo");
        console.log(next);
        console.log(state);
        console.log("Need Login = " + next.data.auth);
        console.log("PassportService isLogin = " + this.PassportService.isLogin);
        console.log("PassportService userData = " + this.PassportService.userData);

        if (next.data.auth === true) {

            if (this.PassportService.isLogin === true) {

                return true;

            }

            if (this.PassportService.isLogin === false) {

                //this.PassportService.getUserData()
                this.http.get("/api/user/data")
                    .subscribe(r => {

                        if ( r.success === true ){

                            this.PassportService.userData = r.content;
                            this.PassportService.isLogin = true;
                            return true;

                        }
                        if ( r.success === false ){

                            this.router.navigateByUrl("/passport/login");

                        }

                    })

            }

        }
        if (next.data.auth === false) {

            return true;

        }

    }

}

Why return true; in subscribe has no effect

< hr >

know that subscribe cannot return something, but how to solve this


the Observable object is returned for asynchronous detection. Here

this.PassportService.getUserData()
                    .subscribe(r => {

                        if ( r.success === true ){

                            this.PassportService.userData = r.content;
                            this.PassportService.isLogin = true;
                            return true;

                        }
                        if ( r.success === false ){

                            this.router.navigateByUrl('/passport/login');

                        }

                    })

does not return data at the outermost layer, and cannot be received outside the return value inside the subscribe


canActivateChild(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {

        if ( this.PassportService.isLogin === false ) {

            return this.PassportService.getUserData()
                .pipe(
                    map((data: any) => {

                        if ( data.success === true ) {

                            this.PassportService.userData.portrait = data.content.portrait
                            this.PassportService.userData.nickname = data.content.nickname
                            this.PassportService.userData.email = data.content.email

                            this.PassportService.isLogin = true

                            return true

                        }

                        if ( data.success === false ) {

                            this.router.navigateByUrl('/passport/login')

                        }

                    })
                )

        } else {

            return true

        }

    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea38c4-1c69.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea38c4-1c69.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?