With Angular 5 deprecating Http and HttpModule in favor of HttpClient and HttpClientModule, I haven't been able to figure out how to pass session tokens around similar to how I used to. For example, this is how I used to do it:
loginUser(loginData) {
this.http.post('http://localhost:3000/login', loginData).subscribe(res => {
localStorage.setItem('token', res.json().token);
})
}
Now that json is the assumed default, how would I do something similar to "res.json().token"? The closest I have found is to use "JSON.stringify", but the problem is it passes the entire json object into the header, not just the token itself. ie;
loginUser(loginData) {
this.http.post('http://localhost:3000/login', loginData).subscribe(res => {
localStorage.setItem('token', JSON.stringify(res));
})
}