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

158
Views
Update User with fetch

Hi im trying to let the user update their account, so i want to delete the users account and then create a new one when im doing it. But it only create a new one, and dosen't delete the one logged in. Please help

user-controller.js

router.put("/update", (req, res) => {
  const user = new userModel(req.body.email, req.body.password);
  db.deleteUser(user);  
  db.saveUser(user);
  res.status(200).send(true);
});

Update.js

document.addEventListener("DOMContentLoaded", (event) => {
   
document.getElementById("update").addEventListener("submit", (event) => {
    event.preventDefault();
  
    const email = document.getElementById("email").value;
    const password = document.getElementById("password").value;
  
    const user = {
      email: email,
      password: password,
    };
  
    fetch("http://localhost:8200/users/update", {
      method: "PUT",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(user),
    })
      .then((response) => response.json())
      .then((response) => {
        if (response) {
          // Gemme oplysninger i localstorage
          localStorage.removeItem("user");
          localStorage.setItem("user", JSON.stringify(user));
          location.href = "/varer.html";
        } else {
          window.alert("Oplysninger forkert");
        }
      })
      .catch(() => {
        window.alert("Der skete en fejl");
      });
  });
});
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!