clientIp property

String get clientIp

Gets the user's IP address for security logging.

Implementation

String get clientIp {
  // Check for forwarded headers first (proxy/load balancer)
  final forwarded = header('x-forwarded-for');
  if (forwarded != null && forwarded.isNotEmpty) {
    return forwarded.split(',').first.trim();
  }

  final realIp = header('x-real-ip');
  if (realIp != null) return realIp;

  // Fallback to connection info
  try {
    return raw.connectionInfo?.remoteAddress.address ?? 'unknown';
  } catch (e) {
    return 'unknown';
  }
}