View Source AshAuthentication.Phoenix.LiveSession (ash_authentication_phoenix v1.8.2)
Ensures that any loaded users which are present in a conn's assigns are also present in a live view socket's assigns.
Typical usage is via the ash_authentication_live_session/2
macro, but can also
manually called like so:
scope "/", ExampleWeb do
pipe_through(:browser)
live_session :authenticated, on_mount: LiveSession, session: {LiveSession, :generate_session, []} do
live "/", ExampleLive
end
end
Summary
Functions
Generate a live session wherein all subject assigns are copied from the conn into the socket.
Supplements the session with any current_X
assigns which are authenticated
resource records from the conn.
Inspects the incoming session for any subject_name -> subject values and loads them into the socket's assigns.
Functions
ash_authentication_live_session(session_name \\ :ash_authentication, opts \\ [], list)
View Source (macro)Generate a live session wherein all subject assigns are copied from the conn into the socket.
Options:
:otp_app
- Set the otp app in which to search for authenticated resources.
All other options are passed through to live_session
, but with session and on_mount hooks
added to set assigns for authenticated resources. Unlike live_session
, this supports
multiple MFAs provided for the session
option. The produced sessions will be merged.
@spec generate_session(Plug.Conn.t(), atom() | [atom()], additional_hooks :: [mfa()]) :: %{ required(String.t()) => String.t() }
Supplements the session with any current_X
assigns which are authenticated
resource records from the conn.
@spec on_mount( atom() | {:set_otp_app, atom()}, %{required(String.t()) => any()}, %{required(String.t()) => any()}, Phoenix.LiveView.Socket.t() ) :: {:cont | :halt, Phoenix.LiveView.Socket.t()}
Inspects the incoming session for any subject_name -> subject values and loads them into the socket's assigns.
For example a session containing {"user", "user?id=aa6c179c-ee75-4d49-8796-528c2981b396"}
becomes an assign called
current_user
with the loaded user as the value.