14 lines
518 B
TypeScript
14 lines
518 B
TypeScript
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
|
import type { Request } from 'express';
|
|
import { RateLimitService } from '../identity/rate-limit.service';
|
|
|
|
@Injectable()
|
|
export class StorefrontGuard implements CanActivate {
|
|
constructor(private readonly limits: RateLimitService) {}
|
|
async canActivate(context: ExecutionContext) {
|
|
const request = context.switchToHttp().getRequest<Request>();
|
|
await this.limits.consume(`storefront:${request.ip}`, 120, 60);
|
|
return true;
|
|
}
|
|
}
|