update auth middleware

This commit is contained in:
Flam3rboy 2021-08-16 15:07:09 +02:00
parent 8a197bbeaa
commit 45f89d4531

View File

@ -8,8 +8,8 @@ export const NO_AUTHORIZATION_ROUTES = [
"/webhooks/", "/webhooks/",
"/ping", "/ping",
"/gateway", "/gateway",
"/experiments" "/experiments",
// /^\/api(\/v\d+)?\/guilds\/\d+\/widget\.(json|png)/ /\/guilds\/\d+\/widget\.(json|png)/
]; ];
export const API_PREFIX = /^\/api(\/v\d+)?/; export const API_PREFIX = /^\/api(\/v\d+)?/;
@ -29,7 +29,13 @@ declare global {
export async function Authentication(req: Request, res: Response, next: NextFunction) { export async function Authentication(req: Request, res: Response, next: NextFunction) {
if (req.method === "OPTIONS") return res.sendStatus(204); if (req.method === "OPTIONS") return res.sendStatus(204);
if (req.url.startsWith("/invites") && req.method === "GET") return next(); // @ts-ignore if (req.url.startsWith("/invites") && req.method === "GET") return next(); // @ts-ignore
if (NO_AUTHORIZATION_ROUTES.some((x) => req.url.startsWith(x) || x.test?.(req.url))) return next(); if (
NO_AUTHORIZATION_ROUTES.some((x) => {
if (typeof x === "string") return req.url.startsWith(x);
return x.test(req.url);
})
)
return next();
if (!req.headers.authorization) return next(new HTTPError("Missing Authorization Header", 401)); if (!req.headers.authorization) return next(new HTTPError("Missing Authorization Header", 401));
try { try {