File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,22 @@ import ms from "ms";
55import isProd from "./is-prod" ;
66
77interface RateLimitConfig {
8+ /**
9+ * The key to use for the rate limit. Usually an IP address or a user ID.
10+ * @default IP address of the request
11+ */
12+ userIdentifier ?: string ;
13+ /**
14+ * A unique identifier for the rate limit.
15+ */
816 identifier : string ;
17+ /**
18+ * The maximum number of requests allowed within the window.
19+ */
920 limit : number ;
21+ /**
22+ * The time window in seconds.
23+ */
1024 windowInSeconds : number ;
1125}
1226
@@ -22,7 +36,7 @@ export async function withRateLimit<T>(
2236 const ip = await getIP ( ) ;
2337
2438 const rateLimitResult = await checkRateLimit ( {
25- key : ip || "" ,
39+ key : config ?. userIdentifier || ip || "" ,
2640 options : {
2741 identifier : config . identifier ,
2842 limit : config . limit ,
You can’t perform that action at this time.
0 commit comments