Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
issue with delete route express.js

In my web application I have a button for deleting user account , when clicked, the user account coudn't be deleted even though I get a 200 status code in the frontend

React

const DeleteAccount = async () => {
    setShow(false);
    setOpenModalLoader(true);
    const id = appAuthState.user._id;
    console.log(" id delete account =>", appAuthState.user._id); // logged properly 
    try {
      const res = await axios.delete(
        "/user/delete",
        { data: { id } },

        { withCredentials: true }
      );
      console.log("deleted user", res.status, res.data); // res.status => 200 , res.data => empty  

      deleteNotify(res.status);

      setOpenModalLoader(false);
      if (res.status === 200) {
        navigate("/");
      }
    } catch (e) {
      console.log("error from delete user", e);
      setOpenModalLoader(false);
      deleteNotify();
    }
  };

express

routerUser.delete("/user/delete", isLoggedIn, async (req, res) => { 
  console.log("request body => ", req.body);   // not logged in cmd 
  try {
    let deletedUser = await User.findByIdAndDelete(req.body.id);
    //console.log("from user delete route", deletedUser); // not logged
    res.status(200).send(deletedUser);
  } catch (e) {
    res.send(e);
  }
});

I'm not getting any errors but console.log inside delete route doesn't log anything in cmd not even "request body => "

Notes:

*) Other routerUser routes work properly with isLoggedIn middleware

*) For a specific reason I don't want to use req.user ,I think req.body should work too

*) If this could help : all other axios calls that work as expected are from localhost:3000/ the deletion call is the only one from localhost:3000/accountdeletion and I'm using cors with the correct configuration (I don't think this is important but who knows)

what I did wrong?

(sorry,english isn't my native language)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!