Hey there, I am currently learning about rxjs and I want to create an observable that returns either true or false.
This is my attempted code:
checkLoggedIn(): Observable<boolean> {
// Check with the server if the user is logged in
if(this._tokenService.getToken()){
// This function returns synchronous true or false
this._httpservice.checkIfLoggedIn()
.subscribe((res) => {
return res.data; // This value will be true or false
},
err => { return false; }
)
} else {
return new Observable(observer => {
observer.next(false);
observer.complete();
});
}
}
How can I modify the 'else' part above to ensure it works with the boolean observable so that in other components I can simply do:
this._authservice.checkLoggedIn()
.subscribe(res => console.log(res));