I'm trying to select two fields from the ngrx store in an Angular Guard like this:
@Injectable()
export class RoleGuard implements CanActivate {
constructor(
public router: ActivatedRouteSnapshot,
private store: Store<AppState> ) {}
canActivate(route: ActivatedRouteSnapshot): Observable<boolean> {
const expectedRole = route.data.Role;
return combineLatest(
this.store.pipe(select(isLoggedIn)),
this.store.pipe(select(currentUser)),
).pipe(
tap( ([loggedIn, user]) =>
{
if ( loggedIn && !(user.role.find(expectedRole) >= 0) ) {
this.router.navigateByUrl('/error/403')
};
}
)
);
}
}
However, I'm getting Type 'boolean | [any, any]' is not assignable to type 'boolean'
, which makes sense, since the combineLatest return the result in array. But I can't seem to find a more elegant way than combineLatest, instead of nesting the two select observable, what would be my alternatives here?