cannery/lib/lokal_web/live/init_assigns.ex
2023-01-26 00:31:13 -05:00

20 lines
537 B
Elixir

defmodule LokalWeb.InitAssigns do
@moduledoc """
Ensures common `assigns` are applied to all LiveViews attaching this hook.
"""
import Phoenix.Component
alias Lokal.Accounts
def on_mount(:default, _params, %{"locale" => locale, "user_token" => user_token}, socket) do
Gettext.put_locale(locale)
socket =
socket
|> assign_new(:current_user, fn -> Accounts.get_user_by_session_token(user_token) end)
{:cont, socket}
end
def on_mount(:default, _params, _session, socket), do: {:cont, socket}
end