protect article delete route

This commit is contained in:
James Shiffer 2020-06-12 08:41:44 -07:00
parent 90724027af
commit 2a81de5bb8

View File

@ -27,6 +27,25 @@ export async function get(req, res, next) {
} }
export async function del(req, res, next) { export async function del(req, res, next) {
if (!req.user) {
res.writeHead(401, {
'Content-Type': 'application/json'
});
res.end(JSON.stringify({
message: `You are not logged in`
}));
return;
}
if (!req.user.author) {
res.writeHead(401, {
'Content-Type': 'application/json'
});
res.end(JSON.stringify({
message: `You are not designated as an author.`
}));
return;
}
const { slug } = req.params; const { slug } = req.params;
const article = await Article.findOneAndDelete({ slug }); const article = await Article.findOneAndDelete({ slug });