diff options
Diffstat (limited to 'lib/aggiedit_web/live/live_helpers.ex')
-rw-r--r-- | lib/aggiedit_web/live/live_helpers.ex | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/aggiedit_web/live/live_helpers.ex b/lib/aggiedit_web/live/live_helpers.ex index aa6b28a..e31fedc 100644 --- a/lib/aggiedit_web/live/live_helpers.ex +++ b/lib/aggiedit_web/live/live_helpers.ex @@ -4,6 +4,9 @@ defmodule AggieditWeb.LiveHelpers do alias Phoenix.LiveView.JS + alias Aggiedit.Accounts + alias Aggiedit.Accounts.User + @doc """ Renders a live component inside a modal. @@ -57,4 +60,13 @@ defmodule AggieditWeb.LiveHelpers do |> JS.hide(to: "#modal", transition: "fade-out") |> JS.hide(to: "#modal-content", transition: "fade-out-scale") end + + def assign_socket_user(session, socket) do + with token when not is_nil(token) <- session["user_token"], + current_user=%User{} = Accounts.get_user_by_session_token(token) do + assign(socket, :current_user, current_user) + else + _ -> socket + end + end end |