Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
taugk committed Dec 18, 2023
1 parent 6061a60 commit a1be5e5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions routes/postsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,16 @@ router.put(
router.delete("/posts/delete/:id", async (req, res) => {
try {
const tokenDecode = req.authData;
if (!tokenDecode || !tokenDecode.id) {
return res.status(401).json({ message: "Unauthorized: Invalid token" });
}
const deletedPost = await Post.destroy({
where: {
id: req.params.id,
userId: tokenDecode.id,
},
});

if (!deletedPost) {
return res
.status(404)
Expand Down

0 comments on commit a1be5e5

Please sign in to comment.