Programming Phoenix LiveView: Missing code snippet / assigns reference (pg 73)

Here, we add two more keys to the socket.assigns. To set the :session_id key, we copy the session ID directly. Then, we use Accounts.get_user_by_session_token/1 to set the :current_user key.

But, there is no actually call to this function in the preceding code snippet. That code snippet is also repeated in the generated PDF. B6

1 Like

The correct code snippet is as follows:

# lib/pento_web/live/wrong_live.ex
def mount(_params, session, socket) do

  {
    :ok,
    assign(
      socket,
      score: 0,
      message: "Guess a number.",
      session_id: session["live_socket_id"],
      current_user: Pento.Accounts.get_user_by_session_token(session["user_token"])
    )
  }
end

Look out for that correction in the next release!

1 Like