philomena/lib/philomena_web/plugs/reload_user_plug.ex
2019-12-16 17:50:15 -05:00

20 lines
392 B
Elixir

defmodule PhilomenaWeb.ReloadUserPlug do
alias Pow.Plug
alias Philomena.Users
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 ->
reloaded_user = Users.get_by(id: user.id)
Plug.assign_current_user(conn, reloaded_user, config)
end
end
end