title: Angular 5 CanActivate only if user Object returned
body: <p>I have an AuthService providing a <code>loggedIn()</code> function, which should return true if logged in and false if not. However, I'm using JWT in order to keep a user logged in. Since I do not only want to check wheter a JWT is expired, but also want to check whether this Token fits to a user, I verify (if a token is stored in the local Storage) this one. How do I return a simple true or false? I tried something like this:</p>
  
  <p>AuthService:</p>
  
  <pre><code>loggedIn(): Observable&lt;boolean&gt; {
      const token = this.loadToken();
      if (token) {
          const headers = this.server.createAuthHeaders(null, null, token);
          const httpOptions = {
              headers
          };
          return this.http.get(url, httpOptions)
          .map(user =&gt; typeof(user) === 'object')
          .catch(err =&gt; Observable.of(false));
      }
      return Observable.of(false);
  }
  </code></pre>
  
  <p>and AuthGuard:</p>
  
  <pre><code>canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
      return this.authService.loggedIn().map((loggedIn) =&gt; {
          if (!loggedIn) {
              this.router.navigate(['/login']);
              return false;
          } else {
              return true;
          }
      }).take(1);
  }
  </code></pre>