Skip to content

Latest commit

 

History

History

nextjs-14-nextauth-4

Arcjet Logo

Arcjet Rate Limit / NextAuth 4 Authentication Example

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.

How to use

  1. From the root of the project, install the SDK dependencies.

    npm ci
  2. Enter this directory and install the example's dependencies.

    cd examples/nextjs-14-nextauth-4
    npm ci
  3. 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.

  4. Start the dev server.

    npm run dev
  5. Visit http://localhost:3000.

  6. Try the different routes linked on the page.