Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Xe Iaso 2024-10-03 08:56:01 -04:00
parent 566a2d5631
commit 5213bec5ce
No known key found for this signature in database

View File

@ -24,19 +24,24 @@ const aj = arcjet({
export default async function middleware(request: NextRequest) { export default async function middleware(request: NextRequest) {
console.log(request.ip); console.log(request.ip);
// const decision = await aj.protect(request); const req = {
// ...request,
// if ( ip: request.headers.get("x-real-ip"),
// // If this deny comes from a bot rule then block the request. You can } as NextRequest;
// // customize this logic to fit your needs e.g. changing the status code.
// decision.isDenied() && const decision = await aj.protect(req);
// decision.reason.isBot()
// ) { if (
// return NextResponse.json({ error: "Unauthorized" }, { status: 403 }); // If this deny comes from a bot rule then block the request. You can
// } else if (decision.isErrored()) { // customize this logic to fit your needs e.g. changing the status code.
// console.warn("Arcjet error", decision.reason.message); decision.isDenied() &&
// return NextResponse.json({ error: "Bad request" }, { status: 400 }); decision.reason.isBot()
// } else { ) {
// return NextResponse.next(); 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();
}
} }