i want save the token and the response object have the token but i cant save it in the localstorage value of the token give me undefined
this the login function
login() {
this.errorMsg = [];
this.authService
.authenticate({
body: this.authRequest,
})
.subscribe({
next: (res) => {
this.tokenService.token = res.token as string;
console.log(res.token);
// this.router.navigate(['books']);
},
error: (err) => {
console.log(err);
if (err.error.validationErrors) {
this.errorMsg = err.error.validationErrors;
} else {
this.errorMsg.push(err.error.error);
}
},
});
}
this is the token service class
export class TokenService {
set token(token: string) {
localStorage.setItem('token', token);
}
get token() {
return localStorage.getItem('token') as string;
}
}