Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda