mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-12 08:08:43 -05:00
12 lines
424 B
TypeScript
12 lines
424 B
TypeScript
const apiTokens = process.env["PUBLIC_API_TOKENS"]?.split(",") ?? [];
|
|
export function requireBearerAuth(req: Request) {
|
|
const authHeader = req.headers.get("Authorization");
|
|
if (!authHeader) {
|
|
throw new Response("Missing Authorization header", { status: 401 });
|
|
}
|
|
const token = authHeader.replace("Bearer ", "");
|
|
if (!apiTokens.includes(token)) {
|
|
throw new Response("Invalid token", { status: 401 });
|
|
}
|
|
}
|