Files
something-erlang/lib/something_erlang_web/live/user_live_auth.ex
Rüdiger Diedrich 7035fe5b2d something awful login data
all the stuff to add 2 fields to the user object and to access the
logged0in user in a liveview session
2022-07-18 15:16:57 +02:00

18 lines
462 B
Elixir

defmodule SomethingErlangWeb.UserLiveAuth do
import Phoenix.LiveView
alias SomethingErlang.Accounts
def on_mount(:default, _params, %{"user_token" => user_token} = _session, socket) do
user = Accounts.get_user_by_session_token(user_token)
socket = assign_new(socket, :current_user, fn -> user end)
if socket.assigns.current_user.confirmed_at do
{:cont, socket}
else
{:halt, redirect(socket, to: "/login")}
end
end
end