Fix getting remote IP behind reverse proxy

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-08-27 15:42:09 +02:00
parent 9b0b753064
commit 7c0b813dce
5 changed files with 18 additions and 3 deletions

View File

@@ -12,8 +12,14 @@ defmodule Mobilizon.Web.Auth.Context do
opts
end
def call(conn, _) do
context = %{ip: to_string(:inet_parse.ntoa(conn.remote_ip))}
def call(%{assigns: %{ip: _}} = conn, _opts), do: conn
def call(conn, _opts) do
set_user_and_ip_in_context(conn)
end
def set_user_and_ip_in_context(conn) do
context = %{ip: conn.remote_ip |> :inet.ntoa() |> to_string()}
context =
case Guardian.Plug.current_resource(conn) do