title: How to pass plug loaded data to LiveView components
body: <p>Hi I'm using different domain names to load different data sets. I'm currently using a custom plug to load the correct domain id based on the hostname. E.g. got this in my <code>endpoint.ex</code> just before the router:</p>
  <pre><code>plug WebApp.DomainCheck
  socket &quot;/live&quot;, Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
  ...
  plug WebApp.Router
  </code></pre>
  <p>And</p>
  <pre><code>defmodule WebApp.DomainCheck do
    import Plug.Conn
    @behaviour Plug
  
    def init([]), do: []
  
    def call(conn, _options \\ []) do
      domains = Model.load_allowed_domains()
      case Map.get(domains, conn.host) do
        nil -&gt;
          conn
          |&gt; resp(401, &quot;Domain not allowed&quot;)
          |&gt; halt()
  
        domain_id -&gt;
          conn
          |&gt; assign(:domain_id, domain_id)
      end
    end
  end
  </code></pre>
  <p>Now this works for normal <code>View</code> as I have the <code>domain_id</code> assign in each of them. But how do I get the <code>domain</code> data injected into my <code>LiveView</code>s as well from a plug?</p>
  <p>Currently I've code duplicated the same domain check into <strong>every LiveViews mount()</strong> page:</p>
  <pre><code>defmodule WebApp.WelcomeLive do
    use WebApp, :live_view
  
    @impl true
    def mount(_args, _session, socket) do
      domains = Model.load_allowed_domains()
      host = socket.host_uri.host
      case Map.get(domains, host) do
        nil -&gt; {:error, &quot;Domain not allowed&quot;}
        domain_id -&gt; {:ok, assign(socket, :domain_id, domain_id)}
      end
    end
  </code></pre>
  <p>Is there any way I can make a plug effective in pushing this data down to the live views without need to add code to each mount?</p>