19 lines
546 B
TypeScript
19 lines
546 B
TypeScript
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
|
|
const ip =
|
|
req.headers["x-forwarded-for"]?.split(",")[0]?.trim() ||
|
|
req.headers["x-real-ip"] ||
|
|
req.connection?.remoteAddress ||
|
|
req.socket?.remoteAddress ||
|
|
req.ip ||
|
|
"unknown";
|
|
|
|
return `auth_${ip}`;
|
|
}
|
|
}
|