I am working on a sample app, where I have a Login Component, which calls authentication service. The service in turns makes an Http call, and based on the response of the call, I need to do something.
In the service, I am using http Post along with subscribe to do stuff when my user is able to login, however, I want my component function to consume this response from my manipulation and proceed accordingly.
Below is the code: Login Component:
this.authService.login(this.userName, this.password)
Authentication Service
return this.http.post('http://localhost:8080/login',{
"username": userName,
"password": password
}).subscribe(data => {
//some stuff
return true;
}, () => return false;
})
I want my LoginComponent to wait till it receives true or false from the service.
One way to do this will be just to return the http call back to component and write whole logic there, but that is not what I am looking forward to. I was hoping if there is a better way to do this.