0

I have a Spring boot backend that authenticates a user against the database and generates a JWT token for the user, now i am trying to setup the frontend with Angular 2, i have a login functions that supposed to request authentication from the backend, and save the the JWT token in localstroge, and redirect the user to /home .

login(event, username, password) {
    event.preventDefault();
    let body = JSON.stringify({ username, password });
    this.http.post('/authenticate', body, { headers: contentHeaders })
      .subscribe(
        response => {
          localStorage.setItem('id_token', response.json().id_token);
          this.router.navigate(['home']);
        },
        error => {
          alert(error.text());
          console.log(error.text());
        }
      );

when a request is sent to authenticate a user, the user is authenticated and Authorization header with a valid jwt token is returned, but no redirection to /home happens, this is because code inside .subscribe() never called. what could possible cause this?. The code is part of this tutorial https://auth0.com/blog/creating-your-first-real-world-angular-2-app-from-authentication-to-calling-an-api-and-everything-in-between/

Claies
  • 22,124
  • 4
  • 53
  • 77
ahmedjaad
  • 683
  • 1
  • 8
  • 14

0 Answers0