cannery/lib/cannery_web/live/init_assigns.ex
shibao 6b565abf93
All checks were successful
continuous-integration/drone/push Build is passing
update to liveview 0.18 and use elixir 1.14
2022-11-07 22:36:38 -05:00

20 lines
541 B
Elixir

defmodule CanneryWeb.InitAssigns do
@moduledoc """
Ensures common `assigns` are applied to all LiveViews attaching this hook.
"""
import Phoenix.Component
alias Cannery.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