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. Bot detection. Rate limiting. Email validation. Attack protection. Data redaction. A developer-first approach to security.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.
See an example Next.js implementation on GitHub.