-Adding Author to Campground
-Showing and Hiding Edit/Delete
-Campground Permissions
Adding Author to Campground
The purpose of adding authentication to the campground is to make sure that the user who is creating the review is who they say they are. The content that is generated by the user can be edited and deleted by the same user and not another user.
Showing and Hiding Edit/Delete
Campground Permissions
router.put('/:id', isLoggedIn, validateCampground, catchAsync(async (req, res) => {
const { id } = req.params;
const campground = await Campground.findById(id);
if (!campground.equal(req.user._id)) {
req.flash('error', 'You do not have permission to do that!');
return res.redirect(`/campgrounds/${id}`);
}
req.flash('success', 'Successfully updated campground!');
res.redirect(`/campgrounds/${campground._id`)
}));
Top comments (0)