philomena/lib/philomena_web/plugs/reload_user_plug.ex
2019-11-17 13:18:21 -05:00

21 lines
No EOL
418 B
Elixir

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