2022-07-25 19:31:54 -04:00
|
|
|
defmodule MemexWeb.InitAssigns do
|
2022-05-05 20:55:59 -04:00
|
|
|
@moduledoc """
|
|
|
|
Ensures common `assigns` are applied to all LiveViews attaching this hook.
|
|
|
|
"""
|
2022-11-16 21:11:02 -05:00
|
|
|
import Phoenix.Component
|
2022-07-25 19:31:54 -04:00
|
|
|
alias Memex.Accounts
|
2022-05-05 20:55:59 -04:00
|
|
|
|
|
|
|
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
|