Add admin check.

This commit is contained in:
Brian Cao 2022-12-27 13:13:59 -08:00
parent c90bd941b5
commit 39ea100f2a
20 changed files with 133 additions and 98 deletions

View file

@ -22,13 +22,10 @@ export default async (
await useCors(req, res);
await useAuth(req, res);
const {
user: { id: userId },
} = req.auth;
const { id: websiteId } = req.query;
if (req.method === 'GET') {
if (!(await canViewWebsite(userId, websiteId))) {
if (!(await canViewWebsite(req.auth, websiteId))) {
return unauthorized(res);
}
@ -38,7 +35,7 @@ export default async (
}
if (req.method === 'POST') {
if (!(await canUpdateWebsite(userId, websiteId))) {
if (!(await canUpdateWebsite(req.auth, websiteId))) {
return unauthorized(res);
}
@ -56,7 +53,7 @@ export default async (
}
if (req.method === 'DELETE') {
if (!(await canDeleteWebsite(userId, websiteId))) {
if (!(await canDeleteWebsite(req.auth, websiteId))) {
return unauthorized(res);
}