I've encountered a weird bug in my program, specifically when I make a call in axios to delete an user.
Axios call:
export const deleteUser = (userData, history) => dispatch => {
console.log(userData);
axios
.delete('http://localhost:5000/api/users/delete', userData, { crossdomain: true })
.then(res => history.push("/login")) // redirect to login on successful removal
.catch(err =>
dispatch({
type: GET_ERRORS,
payload: err.response.data
})
);
};
console prints out userData as expected (I only need the id to delete the user).
{
"id": "5e3143dcf5b0337d90b8df74",
"name": "",
"email": "",
"password": "",
"password2": ""
}
However when I process the call with data I just received on the server side:
router.delete("/delete", (req, res) => {
console.log(req.body);
User.findOneAndRemove({ _id: req.body.id }, {new: true}, function (err, doc) {
if (err) return res.send(500, { error: err });
console.log(doc);
res.status(200).json(doc);
});
});
it prints out:
{}