I try to implement the jwt token with angular2 front-end. When I try receive the token with post method using Postman I receive authorization token but doing so in Angular returns null response object. Here's snippet code of Angular service I use.
return this.http.post(this.authUrl, { username: username, password: password }) .map((response: Response) => { console.log(username + ' ' + password); // login successful if there's a jwt token in the response let token = response.json() && response.json().token; console.log(token); if (token) { // set token property this.token = token; // store username and jwt token in local storage to keep user logged in between page refreshes localStorage.setItem('currentUser', JSON.stringify({ username: username, token: token })); // return true to indicate successful login return true; } else { // return false to indicate failed login return false; } });
The thing is that when I try to log the token is null same with response. For the back-end portion of code I followed this implementation of jwt token.
The only clue I have is that trying to invoke post method like that
this.http.post<any>(this.authUrl, { username: username, password: password }).subscribe();
I receive Subscriber object. Doing so with toPromise() instead of subscribe() I got ZoneAwarePromise but I cannot locate token in both cases.