17 lines
575 B
TypeScript
17 lines
575 B
TypeScript
import type { ExceptionMessage } from "#app/exceptions/handler.ts"
|
|
import { APP_KEY, APP_KEY_HEADER_NAME } from "#config/app.ts"
|
|
import type { HttpContext } from "@adonisjs/core/http"
|
|
import type { NextFn } from "@adonisjs/core/types/http"
|
|
|
|
export default class AppKeySecurityMiddleware {
|
|
public async handle(
|
|
context: HttpContext,
|
|
next: NextFn,
|
|
): Promise<unknown | ExceptionMessage> {
|
|
if (context.request.header(APP_KEY_HEADER_NAME) === APP_KEY) {
|
|
return next()
|
|
}
|
|
return context.response.unauthorized({ message: "Unauthorized access" })
|
|
}
|
|
}
|