Use default Phoenix.LiveView.Socket (#3404)
* Use default Phoenix.LiveView.Socket * Pull socket definition highed in Endpoint config * Simplify runtime plug sessionpull/3432/head
parent
97b24c0492
commit
d7cd719d4f
@ -1,15 +0,0 @@
|
||||
defmodule PlausibleWeb.LiveSocket do
|
||||
use Phoenix.LiveView.Socket
|
||||
require Logger
|
||||
|
||||
def connect(params, %Phoenix.Socket{} = socket, connect_info) do
|
||||
case Phoenix.LiveView.Socket.connect(params, socket, connect_info) do
|
||||
{:ok, %Phoenix.Socket{private: %{connect_info: %{session: nil}}}} ->
|
||||
Logger.error("Could not connect the live socket: no session found")
|
||||
{:error, :socket_auth_error}
|
||||
|
||||
other ->
|
||||
other
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,36 +0,0 @@
|
||||
defmodule PlausibleWeb.Plugs.RuntimeSessionAdapter do
|
||||
@moduledoc """
|
||||
A `Plug.Session` adapter that allows configuration at runtime.
|
||||
Sadly, the plug being wrapped has no MFA option for dynamic
|
||||
configuration.
|
||||
|
||||
This is currently used so we can dynamically pass the :domain
|
||||
and have cookies planted across one root domain.
|
||||
"""
|
||||
|
||||
@behaviour Plug
|
||||
|
||||
@impl true
|
||||
def init(opts) do
|
||||
Plug.Session.init(opts)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def call(conn, opts) do
|
||||
Plug.Session.call(conn, patch_cookie_domain(opts))
|
||||
end
|
||||
|
||||
defp patch_cookie_domain(%{cookie_opts: cookie_opts} = runtime_opts) do
|
||||
Map.put(
|
||||
runtime_opts,
|
||||
:cookie_opts,
|
||||
cookie_opts
|
||||
|> Keyword.put_new(:domain, PlausibleWeb.Endpoint.host())
|
||||
|> Keyword.put(
|
||||
:secure,
|
||||
Application.fetch_env!(:plausible, PlausibleWeb.Endpoint)[:secure_cookie]
|
||||
)
|
||||
)
|
||||
|> Map.put(:key, "_plausible_#{Application.fetch_env!(:plausible, :environment)}")
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue