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