Assigns from router plugs not making it to LiveView sockets

On the 2nd mount, when the websocket connection is established, your socket assigns can’t have :current_user since it doesn’t go through your plug. You don’t have access to the Plug.Conn assigns here.

On the 1st mount, that is the http connection, it does go through your plug, and the current user is fetched by your plug and not again in the mount since you’re using assign_new.

If you were not to use assign_new, but instead assign, you would see 3 queries instead of the 2 you see now.

EDIT: this blog post might clear some things: LiveView: Double Mount | Benjamin Milde

1 Like