 defmodule LeatherWeb.UserController do
   use LeatherWeb, :controller
-  # plug :authenticate when action in [:index]
+
+  plug :forbid_authenticated_users when action in
+        [:login, :login_form, :signup, :signup_form]
   alias Leather.Repo
   alias Leather.User
 

  end


  defp authenticate(conn, _opts) do
    if conn.assigns.current_user do
      conn
    else

      |> halt()
    end
  end


  defp forbid_authenticated_users(conn, _opts) do
    if conn.assigns.current_user do
      conn
      |> redirect(to: "/")
      |> halt()
    else
      conn
    end
  end
end
