On the normal pages in a project I’m using data that gets loaded from a plug. A plug looks like this:
defmodule WebApp1.Plug1 do
import Plug.Conn
def init(options) do
options
end
# simplified
def call(conn, _opts) do
data1_id = get_session(conn, :data1_id)
data1 = get_data1_from_db(data1_id)
assign(conn, :data1, data1)
end
end
Now that I’m rewritting some page to LiveView, I’ve bumped into an error that data1
has become unavailable in a app
layout in which it – data1
– is getting used.
How to fix this?
How make data1
accessible in not a single live view but all the ones that I have and will?
I’m aware of this elixir - How to pass plug loaded data to LiveView components - Stack Overflow
but it suggest that one will have to refer to a session in every single live view from on. Isn’t there a better way?