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