diff --git a/src/middlewares/Authentication.ts b/src/middlewares/Authentication.ts
index 65d5a2cf..30445815 100644
--- a/src/middlewares/Authentication.ts
+++ b/src/middlewares/Authentication.ts
@@ -2,7 +2,13 @@ import { NextFunction, Request, Response } from "express";
import { HTTPError } from "lambert-server";
import { checkToken } from "fosscord-server-util";
-export const NO_AUTHORIZATION_ROUTES = ["/api/v8/auth/login", "/api/v8/auth/register", "/api/v8/webhooks/"];
+export const NO_AUTHORIZATION_ROUTES = [
+ "/api/v8/auth/login",
+ "/api/v8/auth/register",
+ "/api/v8/webhooks/",
+ "/api/v8/gateway",
+ "/api/v8/experiments",
+];
declare global {
namespace Express {
@@ -14,6 +20,8 @@ declare global {
}
export async function Authentication(req: Request, res: Response, next: NextFunction) {
+ if (!req.url.startsWith("/api")) return next();
+ if (req.url.startsWith("/api/v8/invites") && req.method === "GET") return next();
if (NO_AUTHORIZATION_ROUTES.some((x) => req.url.startsWith(x))) return next();
if (!req.headers.authorization) return next(new HTTPError("Missing Authorization Header", 401));
// TODO: check if user is banned/token expired
@@ -22,7 +30,7 @@ export async function Authentication(req: Request, res: Response, next: NextFunc
const decoded: any = await checkToken(req.headers.authorization);
req.token = decoded;
- req.user_id = BigInt(decoded.id);
+ req.user_id = decoded.id;
return next();
} catch (error) {
return next(new HTTPError(error.toString(), 400));
diff --git a/src/middlewares/ErrorHandler.ts b/src/middlewares/ErrorHandler.ts
index 52fa949c..25a68865 100644
--- a/src/middlewares/ErrorHandler.ts
+++ b/src/middlewares/ErrorHandler.ts
@@ -16,14 +16,15 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne
errors = error.errors;
} else {
console.error(error);
- if (req.server.options.production) {
+ if (req.server?.options?.production) {
message = "Internal Server Error";
}
code = httpcode = 500;
}
res.status(httpcode).json({ code: code, message, errors });
- return next();
+
+ return;
} catch (error) {
console.error(error);
return res.status(500).json({ code: 500, message: "Internal Server Error" });
|