Files
simple-proxy/src/proxy/auth.ts
T
2023-04-08 18:32:49 -05:00

18 lines
442 B
TypeScript

import type { Request, Response, NextFunction } from "express";
import { config } from "../config";
const PROXY_KEY = config.proxyKey;
export const auth = (req: Request, res: Response, next: NextFunction) => {
if (!PROXY_KEY) {
next();
return;
}
if (req.headers.authorization === `Bearer ${PROXY_KEY}`) {
delete req.headers.authorization;
next();
} else {
res.status(401).json({ error: "Unauthorized" });
}
};