Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda