Thanks Chris !
setting the user_id in the session worked perfectly.
For anybody following this subject, I ended up with a route like
live "/article/:article_id/edit", EditArticleLive, session: [:path_params, :current_user_id]
However, the assign_new
only half worked for my case. In your example above it would always lookup_user/1
for me when the LV mounts.
If I inspect the conn, the first iteration would be
%Phoenix.LiveView.Socket{
assigns: %{
current_user: %MyApp.Accounts.Schema.User{
__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
id: 3,
...
},
my_text: ""
},
changed: %{current_user: true, my_text: true},
connected?: false,
endpoint: MyAppWeb.Endpoint,
fingerprints: {nil, %{}},
id: "phx-+acWjg8b",
parent_pid: nil,
private: %{
assigned_new: {%{
current_user: %MyApp.Accounts.Schema.User{
__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
id: 3,
...
}
}, [:current_user]}
},
stopped: nil
}
Which looks fine to me.
But then in the second iterations turns into this, if I do not fetch the User
%Phoenix.LiveView.Socket{
assigns: %{current_user: nil, my_text: ""},
changed: %{current_user: true, my_text: true},
connected?: true,
endpoint: MyAppWeb.Endpoint,
fingerprints: {nil, %{}},
id: "phx-noktpWPS",
parent_pid: nil,
private: %{assigned_new: {%{}, [:current_user]}},
stopped: nil
}