clientIp property

String? get clientIp

Get the client IP address

Implementation

static String? get clientIp {
  try {
    final req = request;
    // Try X-Forwarded-For header first (for proxies/load balancers)
    final forwardedFor = req.headers.get('x-forwarded-for');
    if (forwardedFor != null && forwardedFor.isNotEmpty) {
      return forwardedFor.split(',').first.trim();
    }
    // Fall back to remote address
    return req.raw.connectionInfo?.remoteAddress.address;
  } catch (_) {
    return null;
  }
}