Skip to content

Commit

Permalink
feat: pass context to get tracker fn as second arg
Browse files Browse the repository at this point in the history
  • Loading branch information
manuchekhr32 authored and jmcdo29 committed Dec 10, 2024
1 parent 52608f3 commit a3d602e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/throttler-module-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ export interface ThrottlerAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
/**
* @publicApi
*/
export type ThrottlerGetTrackerFunction = (req: Record<string, any>) => Promise<string> | string;
export type ThrottlerGetTrackerFunction = (
req: Record<string, any>,
context: ExecutionContext,
) => Promise<string> | string;

/**
* @publicApi
Expand Down
2 changes: 1 addition & 1 deletion src/throttler.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class ThrottlerGuard implements CanActivate {
}
}
}
const tracker = await getTracker(req);
const tracker = await getTracker(req, context);
const key = generateKey(context, tracker, throttler.name);
const { totalHits, timeToExpire, isBlocked, timeToBlockExpire } =
await this.storageService.increment(key, ttl, limit, blockDuration, throttler.name);
Expand Down

0 comments on commit a3d602e

Please sign in to comment.