const isLoggedIn = (req, res, next) => {
if (req.isAuthenticated()) {
return next();
}
res.redirect('/login');
}
const checkCampgroundOwnership = (req, res, next) => {
if (req.isAuthenticated()) {
Campground.findById(req.params.id, (err, foundCampground) => {
if (err) {
console.log(err);
res.send('something went wrong');
} else {
if (foundCampground.author.id.equals(req.user._id)) {
return next();
} else {
res.redirect('back');
}
}
})
} else {
res.redirect('back');
}
}