module.exports = function(req, res, next) { if (!req.session.userId) { if (req.originalUrl.startsWith("/api/")) { return res.status(401).json({ error: "Je bent niet ingelogd" }); } return res.redirect("/login"); } next(); };