2021-03-19 19:32:18 +00:00
|
|
|
defmodule Legendary.AuthWeb.Helpers do
|
2021-06-19 17:26:20 +00:00
|
|
|
def current_user(socket = %Phoenix.LiveView.Socket{assigns: %{current_user: user}}), do: user
|
|
|
|
def current_user(socket = %Phoenix.LiveView.Socket{assigns: %{__assigns__: %{current_user: user}}}), do: user
|
|
|
|
def current_user(%Phoenix.LiveView.Socket{}), do: nil
|
|
|
|
def current_user(conn), do: Pow.Plug.current_user(conn)
|
|
|
|
|
|
|
|
def has_role?(conn_or_socket, role) do
|
|
|
|
conn_or_socket
|
|
|
|
|> current_user()
|
2021-03-19 19:32:18 +00:00
|
|
|
|> Legendary.Auth.Roles.has_role?(role)
|
2020-10-09 22:08:28 +00:00
|
|
|
end
|
|
|
|
end
|