const checkAuth = (req, res, next) => { if (req.isAuthenticated()) { next(); } else { res.status(401).send('Unauthorized'); } }; app.get('/profile', checkAuth, (req, res) => { res.send('User Profile'); });