defmodule CentralcloudMy.Plugs.RequireAuth do
  import Plug.Conn
  import Phoenix.Controller, only: [redirect: 2]

  def init(opts), do: opts

  def call(conn, _opts) do
    case get_session(conn, :customer_id) do
      nil ->
        conn
        |> redirect(to: "/login")
        |> halt()

      _id ->
        conn
    end
  end
end
