Arcjet helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.
The Arcjet rate limit example below applies a token
bucket rate limit rule to a route where we identify the user based on their ID
e.g. if they are logged in. The bucket is configured with a maximum capacity of
10 tokens and refills by 5 tokens every 10 seconds. Each request consumes 5
tokens.
import arcjet, { tokenBucket } from"@arcjet/next";
import { NextResponse } from"next/server";
const aj = arcjet({
key: process.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.comrules: [
// Create a token bucket rate limit. Other algorithms are supported.tokenBucket({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log onlycharacteristics: ["userId"], // track requests by a custom user IDrefillRate: 5, // refill 5 tokens per intervalinterval: 10, // refill every 10 secondscapacity: 10, // bucket maximum capacity of 10 tokens
}),
],
});
exportasyncfunctionGET(req: Request) {
const userId = "user123"; // Replace with your authenticated user IDconst decision = await aj.protect(req, { userId, requested: 5 }); // Deduct 5 tokens from the bucketconsole.log("Arcjet decision", decision);
if (decision.isDenied()) {
returnNextResponse.json(
{ error: "Too Many Requests", reason: decision.reason },
{ status: 429 },
);
}
returnNextResponse.json({ message: "Hello world" });
}
Shield example
Arcjet Shield protects your application against common
attacks, including the OWASP Top 10. You can run Shield on every request with
negligible performance impact.
bump @typescript-eslint/eslint-plugin from 7.16.1 to 7.17.0 (#1164) (06344e7)
bump @typescript-eslint/parser from 7.16.1 to 7.17.0 (#1165) (40adc5b)
bump eslint-config-turbo from 2.0.6 to 2.0.9 (#1159) (1e7a59f)
dev: bump @rollup/wasm-node from 4.18.1 to 4.19.0 (#1160) (7062ca0)
dev: bump typescript from 5.5.3 to 5.5.4 (#1166) (644e3a6)
example: bump @clerk/nextjs from 5.2.5 to 5.2.6 in /examples/nextjs-14-permit in the dependencies group (#1173) (2dd29a7)
example: bump hono from 4.4.13 to 4.5.1 in /examples/nodejs-hono-rl in the dependencies group across 1 directory (#1158) (797d8b8)
example: bump postcss from 8.4.39 to 8.4.40 in /examples/nextjs-14-app-dir-validate-email in the dependencies group (#1177) (926f84e)
example: bump postcss from 8.4.39 to 8.4.40 in /examples/nextjs-14-clerk-rl in the dependencies group across 1 directory (#1180) (47b6e7d)
example: bump tailwindcss from 3.4.4 to 3.4.6 in /examples/nextjs-14-app-dir-validate-email in the dependencies group across 1 directory (#1139) (ee1938b)
example: bump tailwindcss from 3.4.5 to 3.4.6 in /examples/nextjs-14-app-dir-rl in the dependencies group (#1152) (282448a)
example: bump tailwindcss from 3.4.5 to 3.4.6 in /examples/nextjs-14-decorate in the dependencies group (#1148) (1149de9)
example: bump tailwindcss from 3.4.5 to 3.4.6 in /examples/nextjs-14-ip-details in the dependencies group (#1147) (c77aa6b)
example: bump tailwindcss from 3.4.5 to 3.4.6 in /examples/nextjs-14-nextauth-4 in the dependencies group (#1145) (a97525b)
example: bump tailwindcss from 3.4.5 to 3.4.6 in /examples/nextjs-14-pages-wrap in the dependencies group (#1151) (d9291c6)
example: bump the dependencies group across 1 directory with 2 updates (#1171) (e2bfd35)
example: bump the dependencies group across 1 directory with 2 updates (#1179) (1240621)
example: bump the dependencies group across 1 directory with 3 updates (#1163) (213a7c8)
example: bump the dependencies group across 1 directory with 3 updates (#1178) (9bc5f1e)
example: bump the dependencies group across 1 directory with 3 updates (#1181) (f01ec2c)
example: bump the dependencies group across 1 directory with 5 updates (#1167) (f3c8ca7)
example: bump the dependencies group across 1 directory with 6 updates (#1169) (a02a74c)
🧹 Miscellaneous Chores
examples: Add Next.js app with Permit.io for dynamic Arcjet rules (#1067) (6939878)
FAQs
Arcjet SDK for the Next.js framework
The npm package @arcjet/next receives a total of 1,048 weekly downloads. As such, @arcjet/next popularity was classified as popular.
We found that @arcjet/next demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 2 open source maintainers collaborating on the project.
Package last updated on 24 Jul 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.