From 5213bec5ce38024606fddd6b70f71f84ede0332b Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Thu, 3 Oct 2024 08:56:01 -0400 Subject: [PATCH] fix?? Signed-off-by: Xe Iaso --- middleware.ts | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/middleware.ts b/middleware.ts index 6469a18..399756b 100644 --- a/middleware.ts +++ b/middleware.ts @@ -24,19 +24,24 @@ const aj = arcjet({ export default async function middleware(request: NextRequest) { console.log(request.ip); - // const decision = await aj.protect(request); - // - // if ( - // // If this deny comes from a bot rule then block the request. You can - // // customize this logic to fit your needs e.g. changing the status code. - // decision.isDenied() && - // decision.reason.isBot() - // ) { - // return NextResponse.json({ error: "Unauthorized" }, { status: 403 }); - // } else if (decision.isErrored()) { - // console.warn("Arcjet error", decision.reason.message); - // return NextResponse.json({ error: "Bad request" }, { status: 400 }); - // } else { - // return NextResponse.next(); - // } + const req = { + ...request, + ip: request.headers.get("x-real-ip"), + } as NextRequest; + + const decision = await aj.protect(req); + + if ( + // If this deny comes from a bot rule then block the request. You can + // customize this logic to fit your needs e.g. changing the status code. + decision.isDenied() && + decision.reason.isBot() + ) { + return NextResponse.json({ error: "Unauthorized" }, { status: 403 }); + } else if (decision.isErrored()) { + console.warn("Arcjet error", decision.reason.message); + return NextResponse.json({ error: "Bad request" }, { status: 400 }); + } else { + return NextResponse.next(); + } } \ No newline at end of file