Returned boolean value in rxjs function is not executed
I am new to rxjs and I would like to return the observable to true or false
here is what i tried
checkLoggedin():Observable<boolean> {
//check from server if user is loggdin
if(this._tokenService.getToken()){ //this returns synchronous true or false
this._httpservice.checkifloggedin()
.subscribe((res)=>{
return res.data //this comes in as true or false value
},
err=>{ return false }
)
}else{
return false //this fails with an error of
//type false is not assignable to observable<boolean>
}
}
How do I modify the above part to work with a boolean observable so that in other components I can only do
this._authservice.checkLoggedin()
.subscribe.....//here get the value whether true or false
+3
source to share
2 answers