// route
router.delete("/user/:userId", requireSignin, isAdmin, removeUser);
// controller
export const removeUser = async (req, res) => {
  try {
    const { userId } = req.params;
    if (userId === req.user._id) return; // cant delete yourself
    const user = await User.findByIdAndDelete(userId);
    res.json(user);
  } catch (err) {
    console.log(err);
  }
};
  const handleDelete = async (item) => {
    if (item._id === auth.user._id) {
      alert("You can not delete yourself");
      return;
    }
    try {
      const { data } = await axios.delete(`/user/${item._id}`);
      if (data?.error) {
        toast.error(data.error);
      } else {
        console.log("user deleted", data);
        setUsers((previousUsers) =>
          previousUsers.filter((user) => user._id !== data._id)
        );
        toast.success("User deleted successfully");
      }
    } catch (err) {
      console.log(err);
    }
  };