Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

497
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda