This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
wikipedia-game-solver/apps/api/app/middleware/app_key_security_middleware.ts

17 lines
575 B
TypeScript
Raw Permalink Normal View History

2024-08-18 02:31:02 +02:00
import type { ExceptionMessage } from "#app/exceptions/handler.ts"
2024-08-15 15:14:21 +02:00
import { APP_KEY, APP_KEY_HEADER_NAME } from "#config/app.ts"
2024-08-12 19:19:43 +02:00
import type { HttpContext } from "@adonisjs/core/http"
import type { NextFn } from "@adonisjs/core/types/http"
export default class AppKeySecurityMiddleware {
2024-08-18 02:31:02 +02:00
public async handle(
context: HttpContext,
next: NextFn,
): Promise<unknown | ExceptionMessage> {
2024-08-12 19:19:43 +02:00
if (context.request.header(APP_KEY_HEADER_NAME) === APP_KEY) {
return next()
}
return context.response.unauthorized({ message: "Unauthorized access" })
}
}