File size: 412 Bytes
5bddbd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import type { Request, Response, NextFunction } from "express";

const PROXY_KEY = process.env.PROXY_KEY;

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" });
  }
};