Passing client IP to socket

You only have access to the connection and its assigns on the initial mount.

As a workaround, you could add the :remote_ip to the session in your plug:

def put_client_ip(conn, _), do: Plug.Conn.put_session(conn, :remote_ip, conn.remote_ip)

then, in mount, pattern match on it:

def mount(_params, %{"remote_ip" => remote_ip}, socket) do
...
end
5 Likes