Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

485
Views
Check if a user is logged in - aws amplify, cognito, angular

I am trying to use aws amplify to implement login functionality in an angular app.

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.

In my authService, I am listening to 'auth' 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?

When I debug this particular flow outlined above, I do see that it hits the code where the subject emits true. ie this.isLoggedInSub.next(true);

logincomponent.html

<button (click) ="signInWithGoogle()" type="button" class="btn btn-outline-primary">Login with Google</button>    
<span>is loggedin: {{this.authService.isLoggedIn$ | async}}</span>

loginComponent.ts

async signInWithGoogle() {
    await this.authService.socialSignIn(AuthService.GOOGLE);
  }

auth.service.ts

private isLoggedInSub = new BehaviorSubject<boolean>(false);
isLoggedIn$ = this.isLoggedInSub.asObservable();

constructor() {
    Hub.listen('auth', (data) => {
      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<ICredentials> {
    return Auth.federatedSignIn({
      provider: socialProvider,
    });
  }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!