I'm doing basic routing on my project and I already have all the user routes working but I'm not managing to get a single user by ID. I can get all users, update and delete specific users but I don't know why the get request isn't working. Here's what it looks like:
router.get("/user/:id"),
requireLogin,
(req, res) => {
User.findById(req.params.id)
.then((doc) => {
if (!doc) {
return res.status(403).json({ error: "Invalid user." });
}
return res.status(200).json(doc);
})
.catch((err) => console.error(err));
};