When I post something to the database, I need to retrieve certain data in the response. If that specific data is missing, I have to make another query using await/async. However, I am facing an issue with this setup when debugging the code. The implementation looks like this:
// Service (Endpoints changed)
public login(username: string, password: string) {
let loginDto = { info: new LoginDto(username, password) };
return this.http.post('https://jsonplaceholder.typicode.com/posts', { title: 'Angular POST Request Example' }).pipe(
map(response => {
return this.processLoginResponse(response);
})
);
}
private async processLoginResponse(response) {
let permissions = await this.getPermissionsFromAPI(116677);
this._user = {username: 'Jhon', permissions: permissions};
return this._user
}
private getPermissionsFromAPI(userId): Promise<any> {
return this.http.get('https://jsonplaceholder.typicode.com/todos/1').toPromise();
}
// Component
onSubmit(e) {
const { username, password } = this.formData;
this.authService
.login(username, password)
.subscribe(
data => {
data.then(x => console.log(x));
// things
}
);
}