Angular 角度2+;使用firebase实时数据库验证guard

Angular 角度2+;使用firebase实时数据库验证guard,angular,firebase,firebase-realtime-database,firebase-authentication,Angular,Firebase,Firebase Realtime Database,Firebase Authentication,我试图根据用户在firebase实时数据库上的数据设置角度路由的防护。我已在用户的实时数据库部分()上将管理员权限设置为dashboard:true。我希望仅当用户的数据库中有dashboard:true属性时,才授予输入某些特定路由的权限。我尝试了下面的代码。但它总是重定向到根路由(localhost:4200) canActivate():可观察{ 返回此.firebaseAuth.authState.map(auth=>{ if(auth){ this.authService.getUse

我试图根据用户在firebase实时数据库上的数据设置角度路由的防护。我已在用户的实时数据库部分()上将管理员权限设置为dashboard:true。我希望仅当用户的数据库中有dashboard:true属性时,才授予输入某些特定路由的权限。我尝试了下面的代码。但它总是重定向到根路由(localhost:4200)

canActivate():可观察{
返回此.firebaseAuth.authState.map(auth=>{
if(auth){
this.authService.getUserData(auth.uid).subscribe(userData=>{
if(userData['dashboard']==true){
返回true;
}否则{
this.router.navigate(['/login']);
返回false;
}
})
}否则{
this.router.navigate(['/login']);
返回false;
}
});
}
canActivate():可观察{
返回此.firebaseAuth.authState.switchMap(auth=>{
if(auth)
返回此.authService.getUserData(auth.uid).map(userData=>{
if(userData['dashboard']==true)
返回true;
this.router.navigate(['/login']);
返回false;
});
this.router.navigate(['/login']);
归还(假);
});
}
    canActivate(): Observable<boolean> {

    return this.firebaseAuth.authState.map(auth => {
      if (auth) {
        this.authService.getUserData(auth.uid).subscribe(userData => {
          if (userData['dashboard'] === true) {
            return true;
          } else {
            this.router.navigate(['/login']);
            return false;
          }
        })
      } else {
        this.router.navigate(['/login']);
        return false;
      }
    });
}
canActivate(): Observable<boolean> {

    return this.firebaseAuth.authState.switchMap(auth => {
        if (auth)
            return this.authService.getUserData(auth.uid).map(userData => {
                if (userData['dashboard'] === true)
                    return true;

                this.router.navigate(['/login']);
                return false;
            });

        this.router.navigate(['/login']);
        return of(false);
    });
}