I am attempting to authenticate using Angular with Spring Security.
My backend is functioning perfectly.
The issue lies within this function responsible for the login:
onFormSubmit(authBody: authBody ) {
this.authService.login(authBody)
.subscribe(res => {
console.log(res);
if (res.token) {
localStorage.setItem('token', res.token);
this.router.navigate(['/menu']);
}
}, (err) => {
console.log(err);
});
}
The console.log(res) returns: {username=med, token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtZWQiLCJyb2xlcyI6W10sImlhdCI6MTYzOTA2NzgzOSwiZXhwIjoxNjM5MDcxNDM5fQ.a-DzNNeVRZ6XUPwYnzAk_P_0yFQO5GXwvBds_7RvGs8}
I have been trying to extract the token from this object, but when testing with if(res.token), it returns undefined.
This is my authentication method service:
login(authBody: authBody): Observable<any> {
console.log(authBody.username);
return this.http.post(apiUrl + this.aPILogin, authBody ,{responseType: 'text'})
.pipe(
tap(_ => this.isLoggedIn = true),
catchError(this.handleError('login', []))
);
}
Any suggestions, please?
Thank you!