philomena/lib/philomena_web/plugs/reload_user_plug.ex

21 lines
392 B
Elixir
Raw Normal View History

2019-11-17 19:18:21 +01:00
defmodule PhilomenaWeb.ReloadUserPlug do
2019-10-31 18:57:39 +01:00
alias Pow.Plug
2019-12-16 23:50:15 +01:00
alias Philomena.Users
2019-10-31 18:57:39 +01:00
def init(opts), do: opts
def call(conn, _opts) do
config = Plug.fetch_config(conn)
case Plug.current_user(conn, config) do
nil ->
conn
user ->
2019-12-16 23:50:15 +01:00
reloaded_user = Users.get_by(id: user.id)
2019-10-31 18:57:39 +01:00
Plug.assign_current_user(conn, reloaded_user, config)
end
end
2019-12-16 23:50:15 +01:00
end