title: Angular2 - Role based AuthGuard
body: <p>My goal is to implement an AuthGuard that checks if a user has access to a specific route based on their role and the requested route and allow them to proceed if they have the right role for the route, or redirect them elsewhere if they do not.  </p>
  
  <p>The AuthGuard calls my AuthorizationService which returns an Observable(UserRole).  I am having difficulty evaluating the user's observable and returning a value to canActivate. It is certainly related to my inexperience with RxJS Observables but I cannot seem to get past this one.</p>
  
  <p>I have  <strong>auth.guard.service.ts</strong></p>
  
  <pre><code> canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable&lt;boolean&gt; {        
  
          let url: string = state.url;
  
          var currentUser$ = this.authService.getCurrentUser();
  
          currentUser$.subscribe((currentUser: MyUser) =&gt; {    
  
              if (currentUser.isInternalUser &amp;&amp; url === '/internal') {
                  console.debug("Internal User! Yes");
                  this.router.navigate(['/internal']);
                  return true;
              } else if (currentUser.isExternalUser &amp;&amp; url === '/dashboard') {
                  console.debug("External User! Yes");                    
                  this.router.navigate(['/external']);
                  return true;
              } else {
                  console.debug("Access Denied...");
                  this.router.navigate(['/pagenotfound']);
                  return false;
              }
          });
  
         //return Observable.of(false);  // I need to return something, but this is not what I want to return!!
  
      }
  </code></pre>
  
  <p><strong>auth.service.ts</strong></p>
  
  <pre><code> getCurrentUser() : Observable&lt;MyUser&gt; {
  
          let currentUser$: Observable&lt;MyUser&gt;;
  
          currentUser$ = this.http.get(this.location.prepareExternalUrl('api/v1/userprofile/')) 
              .cache()       
              .map(this.extractData)
              .catch(this.handleError);
  
          console.log("AuthService#getCurrentUser being called.");
  
          return currentUser$;
      }
  </code></pre>
  
  <p>How can I evaluate my currentUser and have <em>canActivate</em> return a boolean observable?</p>