✨ update auth middleware
This commit is contained in:
parent
8a197bbeaa
commit
45f89d4531
@ -8,8 +8,8 @@ export const NO_AUTHORIZATION_ROUTES = [
|
||||
"/webhooks/",
|
||||
"/ping",
|
||||
"/gateway",
|
||||
"/experiments"
|
||||
// /^\/api(\/v\d+)?\/guilds\/\d+\/widget\.(json|png)/
|
||||
"/experiments",
|
||||
/\/guilds\/\d+\/widget\.(json|png)/
|
||||
];
|
||||
|
||||
export const API_PREFIX = /^\/api(\/v\d+)?/;
|
||||
@ -29,7 +29,13 @@ declare global {
|
||||
export async function Authentication(req: Request, res: Response, next: NextFunction) {
|
||||
if (req.method === "OPTIONS") return res.sendStatus(204);
|
||||
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));
|
||||
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user