KHans
KHans

Reputation: 89

JWT token is undefined but it exists in the http response

The code below successfully returns a jwt token from my backend. However, when i try to access the token to save it in the localStorage it is always undefined. How can I access my jwt token?

loginProcess() {
    if (this.loginForm.valid) {
      this.authService.login(this.loginForm.value).subscribe(
        res => {
          console.log(res); // this returns {jwt: "validTokenHere"
          console.log(res.token); // this returns undefined
          localStorage.setItem('token', res.token); // localstorage is 'token' : undefined
        },
        err => console.log(err)
      )
    }
  }

Upvotes: 0

Views: 1217

Answers (1)

Amadou Beye
Amadou Beye

Reputation: 2818

Your Key is jwt

localStorage.setItem('token', res.jwt);

Upvotes: 1

Related Questions