I get the following error when i try to use subscribe. Please help me to fix this error
userLogin(){
this.authService.userLogin(this.loginData)
.subscribe ((value:boolean)=> {
if(value){
this.route.navigate(['/dashboard']);
}
else
{
alert('failed')
}
},error=>{
alert('failed')
})
}
this is authService.userLogin function code. I think there is no any errors in this function code
userLogin(userPayLoad: { username: string; password: string; }):Observable<boolean>{
return this.http.post("http://localhost:3000/auth/login", userPayLoad)
.pipe(
map( (value:any )=>{
if(value){
localStorage.setItem("access_token",value.access_token);
localStorage.setItem("refresh_token",value.refresh_token);
const decryptedUser= this.jwtHelper.decodeToken(value.access_token);
console.log(decryptedUser);
const data={
access_token:value.access_token,
refresh_token:value.refresh_token,
username:decryptedUser.username,
userid: decryptedUser.sub,
tokenExpiration:decryptedUser.exp,
};
this.userInfo.next(data);
return true;
}
return false;
})
)
}
CodePudding user response:
you can return of(true) or of(false) to return observable, Please check Type 'boolean' is not assignable to type 'Observable<boolean>'