April 2020
Intermediate to advanced
716 pages
18h 55m
English
The delete button is only visible if the signed-in user and postedBy user are the same for the specific post being rendered. For the post to be deleted from the database, we will have to set up a delete post API in the backend which will also have a fetch method in the frontend that will be applied when delete is clicked. The route for the delete post API endpoint will be as follows.
mern-social/server/routes/post.routes.js:
router.route('/api/posts/:postId') .delete(authCtrl.requireSignin, postCtrl.isPoster, postCtrl.remove)
The delete route will check for authorization before calling remove on the post by ensuring the authenticated user and postedBy user are the same users. The isPoster method, which is implemented in ...