How to get app.html.heex to use assigns properly with LiveView

“Authentication” just means “login a user”, it’s certainly not a misnomer no matter how simple it is!

I’m assuming you’re getting this error because /cool_page is a different LiveView (which I’m gathering from view: WebInterface.ActivateLive). You have set the default user in the mount of WebInterface.MyAppLive which then redirects to /cool_page which I’m assuming is WebInterface.ActivateLive. Since this is a totally different LiveView, it’s a totally new socket (as @champeric pointed out).

Yes, if you are logging in a user you have to store a successful login id in a session. The thing is, you can’t set session data over a websocket. This is a websocket limitation, not a LiveView one. You will have to create a controller that looks something like this:

defmodule WebInterface.LoginController do
  use Phoenix.Controller

  def login(conn, params) do
    user = Manage.login(params)
    
    conn
    |> put_session(:user_id, user.id)
    |> redirect(to: ~p"/cool_page")
  end
end

This is where on_mount comes in. It’ll look very roughly like this:

def on_mount(:admin, _params, %{"user_id" => user_id}, socket) do
  {:ok, user} = Manage.get_logged_in_user(user_id)

  {:cont, Phoenix.Component.assign_new(socket, :user, user)}
end

These docs are well worth reading—they go into a lot more detail.