From 4687540269a910edc9f5d8dda0f48d77eb908ef5 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:49:42 -0400 Subject: [PATCH] Create direct game bans middleware --- functions/api/game-bans/_middleware.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 functions/api/game-bans/_middleware.ts diff --git a/functions/api/game-bans/_middleware.ts b/functions/api/game-bans/_middleware.ts new file mode 100644 index 0000000..c86d8ca --- /dev/null +++ b/functions/api/game-bans/_middleware.ts @@ -0,0 +1,21 @@ +export async function onRequest(context: RequestContext) { + const { current_user: currentUser } = context.data; + + if (!currentUser) + return new Response('{"error":Not logged in"}', { + headers: { + "content-type": "application/json", + }, + status: 401, + }); + + if (!(currentUser.permissions & (1 << 5))) + return new Response('{"error":"Forbidden"}', { + headers: { + "content-type": "application/json", + }, + status: 403, + }); + + return await context.next(); +}