Assist_Design/apps/bff/src/auth/guards/auth-throttle.guard.ts

20 lines
643 B
TypeScript
Raw Normal View History

2025-08-21 15:24:40 +09:00
import { Injectable } from "@nestjs/common";
import { ThrottlerGuard } from "@nestjs/throttler";
@Injectable()
export class AuthThrottleGuard extends ThrottlerGuard {
protected async getTracker(req: Record<string, any>): Promise<string> {
// Track by IP address for failed login attempts
2025-08-22 17:02:49 +09:00
const forwarded = req.headers["x-forwarded-for"];
const forwardedIp = Array.isArray(forwarded) ? forwarded[0] : forwarded;
2025-08-21 15:24:40 +09:00
const ip =
2025-08-22 17:02:49 +09:00
forwardedIp?.split(",")[0]?.trim() ||
(req.headers["x-real-ip"] as string | undefined) ||
2025-08-21 15:24:40 +09:00
req.socket?.remoteAddress ||
req.ip ||
"unknown";
return `auth_${ip}`;
}
}