DEV Community

Code_Regina
Code_Regina

Posted on

|YelpCamp| Basic Authorization

                -Adding Author to Campground 
                -Showing and Hiding Edit/Delete
                -Campground Permissions 
Enter fullscreen mode Exit fullscreen mode

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.

Alt Text

Alt Text

Showing and Hiding Edit/Delete

Alt Text

Alt Text

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`)
 })); 

Enter fullscreen mode Exit fullscreen mode

Top comments (0)