Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ency07/B2B/llms.txt
Use this file to discover all available pages before exploring further.
checkRateLimit (src/lib/utils/rate-limiter.ts) provides lightweight in-process rate limiting for Server Actions. It uses an in-memory Map to track request counts per identifier with a configurable time window. It is used in the wizard to prevent form submission abuse.
API Reference
checkRateLimit(identifier, maxRequests?, windowMs?)
Unique key for the rate-limited entity. Typically
"action:email" or "action:ip". Example: "wizard:user@company.com"Maximum number of requests allowed in the window. Defaults to
10.Window duration in milliseconds. Defaults to
60_000 (1 minute).true if the request is within the rate limit; false if the limit is exceeded.Number of remaining requests in the current window. Returns
0 when the rate limit is exceeded.Usage in the Wizard
How It Works
Entries are stored internally as{ count: number; resetAt: number } in a module-level Map.
On each call to checkRateLimit:
- Window expired — if no entry exists for the identifier, or if
Date.now() > entry.resetAt, the entry is reset to{ count: 1, resetAt: now + windowMs }and the request is allowed. - Limit reached — if
entry.count >= maxRequests, returns{ allowed: false, remaining: 0 }without incrementing the counter. - Within window — if the entry is active and below the limit,
countis incremented and{ allowed: true, remaining: maxRequests - entry.count }is returned.