Router Einzigartige Validierung für Mongoose

router.post("/register", async (req, res) => {
  try {
    const { email, password } = req.body;

    let user = await User.findOne({ email });
    if (user) return res.status(400).send("User already registered.");

    user = new User({ email, password });
    user.password = await bcrypt.hash(user.password, 10);
    await user.save();

    res.send("registered");
  } catch (err) {
    console.log(err);
    res.status(500).send("Something went wrong");
  }
});
Khadidja Arezki