title: How to use an observable in angular 2 guards' canActivate()
body: <p>I have created an authentication guard for my angular2 rc5 application.</p>
  
  <p>I am also using a redux store. In that store I keep the user's authentication state. </p>
  
  <p>I read that the guard can return an observable or promise (<a href="https://angular.io/docs/ts/latest/guide/router.html#!#guards" rel="nofollow">https://angular.io/docs/ts/latest/guide/router.html#!#guards</a>)</p>
  
  <p>I can't seem to find a way for the guard to wait until the store/observable is <strong>updated</strong> and only <strong>after</strong> that update return the guard because the default value of the store will always be false.</p>
  
  <p>First try:</p>
  
  <pre><code>@Injectable()
  export class AuthGuard implements CanActivate {
  
    @select(['user', 'authenticated']) authenticated$: Observable&lt;boolean&gt;;
  
    constructor() {}
  
    canActivate(): Promise&lt;boolean&gt; {
  
      return new Promise((resolve, reject) =&gt; {
  
        // updated after a while -&gt;
        this.authenticated$.subscribe((auth) =&gt; {
  
          // will only reach here after the first update of the store
          if (auth) { resolve(true); }
  
          // it will always reject because the default value
          // is always false and it takes time to update the store
          reject(false);
  
        });
  
      });
  
    }
  
  }
  </code></pre>
  
  <p>Second try:</p>
  
  <pre><code>@Injectable()
  export class AuthGuard implements CanActivate {
  
    @select(['user', 'authenticated']) authenticated$: Observable&lt;boolean&gt;;
  
    constructor() {}
  
    canActivate(): Promise&lt;boolean&gt; {
  
      return new Promise((resolve, reject) =&gt; {
  
        // tried to convert it for single read since canActivate is called every time. So I actually don't want to subscribe here. 
        let auth = this.authenticated$.toPromise(); 
  
        auth.then((authenticated) =&gt; {
  
          if (authenticated) { resolve(true); }
  
          reject(false);
  
        });
  
        auth.catch((err) =&gt; {
          console.log(err);
        });
  
    }
  
  }
  </code></pre>