Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
Calling .subscribe() after .pipe(); not executing my redirection code

I have an AuthService with these methods:

signUp = (data: SignUp): Observable<AuthResponseData> => {
  const endpoint = `${env.authBaseUrl}:signUp?key=${env.firebaseKey}`;
  return this._signInOrSignUp(endpoint, data);
};

signIn = (data: SignIn): Observable<AuthResponseData> => {
  const endpoint = `${env.authBaseUrl}:signInWithPassword?key=${env.firebaseKey}`;
  return this._signInOrSignUp(endpoint, data);
};

private _signInOrSignUp = (endpoint: string, data: SignIn | SignUp): Observable<AuthResponseData> => {
  return this.http.post<AuthResponseData>(endpoint, {
    ...data,
    returnSecureToken: true
  }).pipe(
    catchError(error => this._throwError(error)),
    tap(response => this._createAndEmitUserSubject(response)),
  );
}

private _throwError = error => {
  const errorMessage = error.error.error.message;
  return throwError(errorMessage);
};

private _createAndEmitUserSubject = (response: AuthResponseData) => {
  const expirationDate = new Date(new Date().getTime() + +response.expiresIn * 1000);
  const user = new User(
    response.idToken,
    response.email,
    response.idToken,
    expirationDate
  );

  localStorage.setItem("user", JSON.stringify(user));
  this.user$.next(user);
};

And in the sign-in and sign-up components, I call the those in following way:

submit = (): void => {
  if (this.loginForm.invalid) {
    return;
  }

  this.authService
    .signIn(this.loginForm.value)
    .subscribe({
      next: () => this.router.navigate(["/recipes"]),
      error: error => this.error = error
    });
};

But the code within next is not executed. If I remove .pipe() it is. I was hoping I did not need to use .pipe() in two places.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Looks like this._throwError doesn't throw an error. If it was, next couldn't be called later. You are probably not throw'ing error in it and instead returning some value that goes into next

about 4 years ago · Juan Pablo Isaza Relatório

0

Removing this.user$.next(user) solves it, and I did't realize I did not need this at all, but I'd like to know why it blocked the flow.

private _createAndEmitUserSubject = (response: AuthResponseData) => {
  // ...

  localStorage.setItem("user", JSON.stringify(user));
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda