title: Check if a user is logged in - aws amplify, cognito, angular
body: <p>I am trying to use aws amplify to implement login functionality in an angular app. </p>
  
  <p>When I click on the "Login with Google" button, it takes me to the google login page and brings me back to my home page when I provide valid google credentials. </p>
  
  <p>In my authService, I am listening to <code>'auth'</code> event. So when a user is logged in, the subject "isLoggedInSub " emits a "true" value. I am trying to display the value of "isLoggedIn$" observable that is made out of this subject. But it always displays false. As you can see in my html page, I am using async pipe to display the value. Why is the value true not being displayed? </p>
  
  <p>When I debug this particular flow outlined above, I do see that it hits the code where the subject emits true. ie <code>this.isLoggedInSub.next(true);</code></p>
  
  <p><strong>logincomponent.html</strong></p>
  
  <pre><code>&lt;button (click) ="signInWithGoogle()" type="button" class="btn btn-outline-primary"&gt;Login with Google&lt;/button&gt;    
  &lt;span&gt;is loggedin: {{this.authService.isLoggedIn$ | async}}&lt;/span&gt;
  </code></pre>
  
  <p><strong>loginComponent.ts</strong></p>
  
  <pre><code>async signInWithGoogle() {
      await this.authService.socialSignIn(AuthService.GOOGLE);
    }
  </code></pre>
  
  <p><strong>auth.service.ts</strong></p>
  
  <pre><code>private isLoggedInSub = new BehaviorSubject&lt;boolean&gt;(false);
  isLoggedIn$ = this.isLoggedInSub.asObservable();
  
  constructor() {
      Hub.listen('auth', (data) =&gt; {
        switch (data.payload.event) {
          case 'signIn':
            this.isLoggedInSub.next(true);
            break;
          case 'signOut':
            this.isLoggedInSub.next(false);
            break;
          case 'signIn_failure':
            break;
          default:
            break;
        }
      });
    }
  
  socialSignIn(socialProvider: CognitoHostedUIIdentityProvider): Promise&lt;ICredentials&gt; {
      return Auth.federatedSignIn({
        provider: socialProvider,
      });
    }
  </code></pre>