I have an express router set up and I want only authorized users to access its routes. I am currently using passport middleware. Instead of adding a check for req.user
in every endpoint, is there a more efficient way to handle this?
router.get("/", async (req, res) => {
if (!req.user) {
return res.sendStatus(401).send({ message: "Unauthorized" });
}
//logic
res.sendStatus(200).send({message: "OK"})
});