Skip to content

Commit

Permalink
Added a validation on the single story route
Browse files Browse the repository at this point in the history
Checks if the story is private and if the user of the request is the same user of the story.
  • Loading branch information
rafasfz committed Sep 1, 2020
1 parent efe8ee5 commit fd63c8e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions routes/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ router.get('/:id', ensureAuth, async (req, res) => {
return res.render('error/404')
}

res.render('stories/show', {
story,
})
if (story.user._id != req.user.id && story.status == 'private') {
res.render('error/404')
} else {
res.render('stories/show', {
story,
})
}
} catch (err) {
console.error(err)
res.render('error/404')
Expand Down

0 comments on commit fd63c8e

Please sign in to comment.