Arcjet / Clerk integration
Arcjet and Clerk work well together to provide rate limiting based on user authentication. Clerk provides the user authentication and Arcjet provides the rate limiting.
What is Arcjet?
Arcjet helps developers protect their apps in just a few lines of code. Implement rate limiting, bot protection, email verification & defend against common attacks.Example use case
- Limiting access to a free API endpoint based on the client IP address.
- Providing a higher rate limit for authenticated clients based on their Clerk user ID.
See an example Next.js implementation on GitHub.
Rate limits using Clerk user ID
Arcjet rate limits allow custom
characteristics to
identify the client and apply the limit. Using Clerkâs
currentUser()
(app
router) or getAuth()
(pages router) helpers you can pass through a user ID.
Chaining middleware
If you want to protect every page with Arcjet Shield automatically you can run it through Next.js middleware. Clerk also uses middleware to add authentication to your pages. You can chain the two together.