The owner's sign-in to the beamlet's own pages.
The sign-in is kept in a cookie of its own, scoped to /beamlet,
apart from your endpoint's session.
The one part you use is session_options/0, for the socket the
beamlet's own pages connect to:
socket "/beamlet/app/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [session: {Beamlet.Web.Auth, :session_options, []}]]Beamlet.Router and the beamlet's pages use the rest.
Summary
Functions
Assigns :current_user from the session.
Signs the owner in.
Signs the owner out.
The hooks for a live_session.
Halts a signed-out request with a redirect to the login page.
The Plug.Session options for the sign-in's cookie.
Functions
@spec fetch_current_user(Plug.Conn.t(), keyword()) :: Plug.Conn.t()
Assigns :current_user from the session.
It is nil when nobody is signed in.
@spec log_in(Plug.Conn.t(), %Beamlet.User{ __meta__: term(), email: term(), id: term(), inserted_at: term(), password: term(), password_hash: term(), updated_at: term() }) :: Plug.Conn.t()
Signs the owner in.
It creates a session, renews the cookie, and stores the session's secret and the id the app's LiveView sockets on it take.
@spec log_out(Plug.Conn.t()) :: Plug.Conn.t()
Signs the owner out.
It disconnects the app's LiveViews on the session, deletes the session, and clears and renews the cookie.
@spec on_mount( :require_auth | :fetch_current_user, map(), map(), Phoenix.LiveView.Socket.t() ) :: {:cont, Phoenix.LiveView.Socket.t()} | {:halt, Phoenix.LiveView.Socket.t()}
The hooks for a live_session.
:require_auth assigns :current_user, or halts with a redirect
to the login page. :fetch_current_user assigns it, nil when
nobody is signed in.
@spec require_auth(Plug.Conn.t(), keyword()) :: Plug.Conn.t()
Halts a signed-out request with a redirect to the login page.
The path of a GET is stored, so the sign-in returns there.
@spec session_options() :: keyword()
The Plug.Session options for the sign-in's cookie.
Beamlet.Router plugs them in for the beamlet's own pages, and your
endpoint names them for the socket at /beamlet/app/live.