1

I am using combineLatest(which combines the values from all the Observables passed as arguments) in the canActivate method.

My understanding is that, whenever any one of the observables fires, the canActivate observable needs to fire. But that is not happening

In my AuthorizationGuard, I have the following canActivate method -

public canActivate(route: Route): Observable<boolean> {
    return combineLatest(this.service1.checkRoles(route.routeConfig.data.roles),
                         this.service2.serviceLoadedSub).pipe(
                         map(([isAuthorized, permissions]) => {

        console.log('permission in auth guard');
        console.log(permissionSet);

        // some auth checks
        return isAuthorized;
}

service1 checkRoles-

public checkRoles(roles: string[]): Observable<boolean> {
    return this.existingRoles.pipe(
      map(roleMap => {
         // perform some checks

         return true;

      })
    );
  }

service 2 -

export class Service2 {
     public serviceLoadedSub: BehaviorSubject<Set<string>> = new BehaviorSubject<Set<string>>(null);

     constructor (private restService: RestService) {
          this.resService.get('url-info').subscribe(data => {

               serviceLoadedSub.next(new Set(data));
          }
      }
}

So, when service 2 load completes...the behavior subject is fired again.

But for some reason, the observable in canActiavte does not get fired.

Any idea why?

Swinkaran
  • 1,207
  • 1
  • 12
  • 19

0 Answers0