Current section

Files

Jump to
ash_authentication_phoenix lib ash_authentication_phoenix components helpers.ex
Raw

lib/ash_authentication_phoenix/components/helpers.ex

defmodule AshAuthentication.Phoenix.Components.Helpers do
@moduledoc """
Helpers which are commonly needed inside the various components.
"""
alias Phoenix.LiveView.Socket
@doc """
The LiveView `Socket` contains a reference to the Phoenix endpoint, and from
there we can extract the `otp_app` of the current request.
This is pulled from `assigns[:otp_app]`, or inferred
from the socket if that is not set.
"""
@spec otp_app_from_socket(Socket.t()) :: atom
def otp_app_from_socket(socket) do
socket.assigns[:otp_app] ||
:otp_app
|> socket.endpoint.config()
end
@doc """
The LiveView `Socket` contains a refererence to the Phoenix router, and from
there we can generate the name of the route helpers module.
"""
@spec route_helpers(Socket.t()) :: module
def route_helpers(socket) do
Module.concat(socket.router, Helpers)
end
end