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
This commit is contained in:
2022-07-18 15:16:57 +02:00
parent 3e8f4ef042
commit 7035fe5b2d
12 changed files with 129 additions and 62 deletions

View File

@ -0,0 +1,17 @@
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