This commit is contained in:
Your Name committed 2026-06-15 08:24:07 -04:00
1 parent a128b9c163
commit 7a352d4998
77 files changed
+5481 -21

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { Elysia } from "elysia";
import { jwt } from "@elysiajs/jwt";
export const adminOnly = new Elysia({ name: "adminOnly" })
.use(jwt({
name: "jwt",
secret: process.env.JWT_SECRET || "fallback-secret"
}))
.onBeforeHandle(async ({ jwt, headers, set }) => {
const auth = headers.authorization;
if (!auth?.startsWith("Bearer ")) {
set.status = 401;
return { error: "Unauthorized: Missing or invalid token format" };
}
const token = auth.substring(7);
const payload = await jwt.verify(token);
if (!payload) {
set.status = 401;
return { error: "Unauthorized: Invalid token" };
}
if (payload.role !== "ADMIN") {
set.status = 401;
return { error: "Unauthorized: Admin access required" };
}
});
//# sourceMappingURL=auth.js.map