diff --git a/backend/src/middlewares/adminAuth.ts b/backend/src/middlewares/adminAuth.ts index d01e906..a39d468 100644 --- a/backend/src/middlewares/adminAuth.ts +++ b/backend/src/middlewares/adminAuth.ts @@ -1,10 +1,11 @@ import Elysia from "elysia"; export const adminAuth = new Elysia({ name: "adminAuth" }) - .onBeforeHandle(({ headers, set }) => { + .onBeforeHandle(({ headers }) => { const token = headers["authorization"]?.replace("Bearer ", ""); - if (!token || token !== process.env.ADMIN_SECRET) { - set.status = 401; - return { message: "Unauthorized" }; - } + if (!token || token !== process.env.ADMIN_SECRET) + return new Response(JSON.stringify({ message: "Unauthorized" }), { + status: 401, + headers: { "Content-Type": "application/json" }, + }); }); diff --git a/backend/src/routes/admin.ts b/backend/src/routes/admin.ts index f21f2a2..703f930 100644 --- a/backend/src/routes/admin.ts +++ b/backend/src/routes/admin.ts @@ -1,11 +1,17 @@ import Elysia, { t } from "elysia"; -import { adminAuth } from "../middlewares/adminAuth"; import { subjectService } from "../services/subject"; import { eventService } from "../services/event"; import { whitelistModel } from "../models/whitelist"; export const adminRoutes = new Elysia({ prefix: "/admin" }) - .use(adminAuth) + .onBeforeHandle(({ headers }) => { + const token = headers["authorization"]?.replace("Bearer ", ""); + if (!token || token !== process.env.ADMIN_SECRET) + return new Response(JSON.stringify({ message: "Unauthorized" }), { + status: 401, + headers: { "Content-Type": "application/json" }, + }); + }) .post( "/subjects", async ({ body }) => {