diff --git a/apps/fg_http/lib/fg_http_web/live/new_device_live.ex b/apps/fg_http/lib/fg_http_web/live/new_device_live.ex index 5a13536e5..8e68ccf47 100644 --- a/apps/fg_http/lib/fg_http_web/live/new_device_live.ex +++ b/apps/fg_http/lib/fg_http_web/live/new_device_live.ex @@ -8,15 +8,14 @@ defmodule FgHttpWeb.NewDeviceLive do alias FgHttp.Devices.Device alias FgHttpWeb.Router.Helpers, as: Routes - def mount(_params, %{}, socket) do - user_id = "1" - if connected?(socket), do: wait_for_device(socket) + def mount(_params, %{"current_user_id" => user_id}, socket) do + if connected?(socket), do: wait_for_device_connect(socket) device = %Device{id: "1", user_id: user_id} {:ok, assign(socket, :device, device)} end - defp wait_for_device(_socket) do + defp wait_for_device_connect(_socket) do # XXX: pass socket to fg_vpn somehow :timer.send_after(3000, self(), :update) end diff --git a/apps/fg_http/lib/fg_http_web/templates/device/new.html.eex b/apps/fg_http/lib/fg_http_web/templates/device/new.html.eex index 4e41714ba..b2ff5a818 100644 --- a/apps/fg_http/lib/fg_http_web/templates/device/new.html.eex +++ b/apps/fg_http/lib/fg_http_web/templates/device/new.html.eex @@ -1,6 +1,6 @@

New Device

-<%= live_render(@conn, FgHttpWeb.NewDeviceLive) %> +<%= live_render(@conn, FgHttpWeb.NewDeviceLive, session: %{"current_user_id" => @conn.assigns.current_user.id}) %>

<%= link "Back", to: Routes.device_path(@conn, :index) %> diff --git a/apps/fg_http/test/fg_http_web/controllers/device_controller_test.exs b/apps/fg_http/test/fg_http_web/controllers/device_controller_test.exs index 9f594aab3..0b5f37b0e 100644 --- a/apps/fg_http/test/fg_http_web/controllers/device_controller_test.exs +++ b/apps/fg_http/test/fg_http_web/controllers/device_controller_test.exs @@ -27,6 +27,9 @@ defmodule FgHttpWeb.DeviceControllerTest do describe "new device" do test "renders form", %{conn: conn} do + # Mock authentication + conn = Plug.Conn.assign(conn, :current_user, fixture(:user)) + conn = get(conn, Routes.device_path(conn, :new)) assert html_response(conn, 200) =~ "New Device" end