This example shows how to use an Arcjet rate limit with a user ID from NextAuth 4 authentication and Next.js.
It sets up the /api/arcjet
route.
- Unauthenticated users receive a low rate limit based on the user IP address.
- Users authenticated with NextAuth have a higher rate limit based on the user email.
- A bot detection rule is also added to check all requests.
-
From the root of the project, install the SDK dependencies.
npm ci
-
Enter this directory and install the example's dependencies.
cd examples/nextjs-14-nextauth-4 npm ci
-
Rename
.env.local.example
to.env.local
and fill in the required environment variables. You will need to create a GitHub OAuth app for testing. -
Start the dev server.
npm run dev
-
Visit
http://localhost:3000
. -
Try the different routes linked on the page.