Skip to content

IP protection in Middleware #3632

Answered by davidmytton
lorenzobalzani asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @lorenzobalzani - thanks for reaching out! To do this you will need to call the Arcjet protect() method from within the authMiddleware. Using our createMiddleware wrapper is useful if you just want the default behavior, but for something custom like the IP address country lookup you'll need to inspect the decision.

Here's a modified version of your code where requests from China will be blocked. You can add additional country codes into the array to block them. There are other examples at https://docs.arcjet.com/blueprints/ip-geolocation

import arcjet, { createMiddleware, detectBot, shield } from '@arcjet/next';
import NextAuth from 'next-auth';
// eslint-disable-next-line @typescript-…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lorenzobalzani
Comment options

Answer selected by lorenzobalzani
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants