Skip to content

Commit

Permalink
fix(ratelimit): invoke value during runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitMY committed Oct 21, 2024
1 parent b6867d1 commit e7b5faf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions functions/src/middlewares/unkey-ratelimit.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export function rateLimitHeaders(res: Response, ratelimitResponse: RatelimitResp
}

export function unkeyRatelimit(namespace: string, limit: number, duration: Duration) {
const unkeyRootKey = defineString('UNKEY_ROOT_KEY').value();
const unkeyRootKey = defineString('UNKEY_ROOT_KEY');

return async function (req: Request, res: Response, next: NextFunction) {
const rawIdentifier = requestIp.getClientIp(req) ?? 'unknown';
const saltedIdentifier = rawIdentifier + unkeyRootKey;
const saltedIdentifier = rawIdentifier + unkeyRootKey.value();
const identifier = createHash('sha256').update(saltedIdentifier).digest('hex');

const rateLimit = new Ratelimit({
rootKey: unkeyRootKey,
rootKey: unkeyRootKey.value(),
namespace,
limit,
duration,
Expand Down

0 comments on commit e7b5faf

Please sign in to comment.