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:
17
lib/something_erlang_web/live/user_live_auth.ex
Normal file
17
lib/something_erlang_web/live/user_live_auth.ex
Normal 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
|
Reference in New Issue
Block a user