Hi, I’m new to phoenix/elixir
After reading some doc and post, I’m aware that assign/assign to a socket require a liveview
But while I inspect the code in the generated template, like user_auth.ex
use GhostCmsLiveWeb, :verified_routes
import Plug.Conn
import Phoenix.Controller
alias GhostCmsLive.Accounts
...
def on_mount(:mount_current_user, _params, session, socket) do
{:cont, mount_current_user(socket, session)}
end
defp mount_current_user(socket, session) do
Phoenix.Component.assign_new(socket, :current_user, fn ->
if user_token = session["user_token"] do
Accounts.get_user_by_session_token(user_token)
end
end)
end
...
these code seems to work without liveView? is there something I’m missing
And while I implement my own module like the user_auth above
def on_mount(:mount_current_route, _params, session, socket) do
{:cont, mount_current_route(socket, session)}
end
def mount_current_route(socket, session) do
IO.inspect(session["current_path"], label: "Session current_path")
Phoenix.Component.assign_new(socket, :current_path, fn ->
session["current_path"]
end)
end
this assign_new does not work, there is no key in the socket.assigns
so what I’m I missing? great thanks