From 1338e87238e3d85338b93acfd3d1bc91e397df90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Tue, 3 Oct 2023 00:33:54 -0400 Subject: [PATCH] feat(api/utils): add isadmin check --- lib/server/middlewareButNotReally/isAdmin.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/server/middlewareButNotReally/isAdmin.ts diff --git a/lib/server/middlewareButNotReally/isAdmin.ts b/lib/server/middlewareButNotReally/isAdmin.ts new file mode 100644 index 0000000..a109b0b --- /dev/null +++ b/lib/server/middlewareButNotReally/isAdmin.ts @@ -0,0 +1,10 @@ +import { H3Event, EventHandlerRequest } from "h3"; +import { messages } from "../constants"; +export default function (ev: H3Event) { + if (!ev.context.currentUser?.profile.isAdmin) { + throw createError({ + statusCode: 403, + statusMessage: messages[403], + }); + } +}