I have this function that finds an object to my database and should return it, I put a conse.log before to see if there it is the object I want to get and works correctly.
Here it is my service:
buscarUsuario(email: string){
return this.http.post(`${URL}/user/email`, email)
.subscribe(resp => {
//Here i can see the object and works
console.log(resp['usuario']);
//This return doesn't work
return resp['usuario'];
});
}
And here it is the function of my backend, this one I tested it in Postman and works correctly:
userRoutes.post('/email', async(req: Request, res: Response) => {
const usuario = await Usuario.findOne({email: req.body.email});
res.json({
ok: true,
usuario
});
});
So, can anyone tell me how to return that object? Please :)