Session cookie with Phoenix LiveView
You can use phx-trigger-action
to make sure a form submit goes through http instead through the socket.
On the example below, when @trigger_submit
is true
then the form will be sumitted to the path Routes.user_session_path(@socket, :create)
, which will hit the controller and set the cookie:
<%= f = form_for @changeset, Routes.user_session_path(@socket, :create), phx_trigger_action: @trigger_submit, phx_change: :validate, phx_submit: :submit, as: :user %>
<%= input f, :email %>
<%= input f, :password %>
<%= submit "Sign In", disabled: !@changeset.valid? %>
</form>
Tweet