adds auth

This commit is contained in:
nai-degen 2023-04-08 04:12:48 -05:00 committed by nai-degen
parent e1606e3f66
commit bbfb922dab
1 changed files with 15 additions and 0 deletions

15
src/auth.ts Normal file
View File

@ -0,0 +1,15 @@
import type { Request, Response, NextFunction } from "express";
const PROXY_KEY = process.env.PROXY_KEY;
export function auth(req: Request, res: Response, next: NextFunction) {
if (!PROXY_KEY) {
next();
return;
}
if (req.headers.authorization === `Bearer ${PROXY_KEY}`) {
next();
} else {
res.status(401).json({ error: "Unauthorized" });
}
}