diff --git a/src/controllers/auth-middleware.ts b/src/controllers/auth-middleware.ts deleted file mode 100644 index 1d3fa4e..0000000 --- a/src/controllers/auth-middleware.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { IHttpServerComponent } from "@well-known-components/interfaces"; -import { Context, StatusCode } from "../types"; - -async function withAuthTokenValidation( - context: IHttpServerComponent.DefaultContext>, - next: () => Promise -): Promise { - // Validate Authorization header - const authHeader = context.request.headers.get("Authorization"); - if (!authHeader || !authHeader.startsWith("Bearer ")) { - return { - status: StatusCode.UNAUTHORIZED, - body: { - ok: false, - message: "Missing or invalid Authorization header", - }, - }; - } - - const token = authHeader.slice(7); // Extract token after 'Bearer ' - const expectedToken = process.env.AUTH_TOKEN; - - if (token !== expectedToken) { - return { - status: StatusCode.UNAUTHORIZED, - body: { - ok: false, - message: "Invalid authorization token", - }, - }; - } - - return next(); -} - -export { withAuthTokenValidation };