Beacon.LiveAdmin.Router (Beacon LiveAdmin v0.4.2)

View Source

Routing for Beacon LiveAdmin.

Summary

Functions

Mount Beacon LiveAdmin routes to manage running sites in the cluster.

Generates the root path with the admin prefix.

Generates a path with the proper admin prefix for a site.

Generate the path to serve files in priv/static.

Types

conn_or_socket()

@type conn_or_socket() :: Phoenix.LiveView.Socket.t() | Plug.Conn.t()

Functions

beacon_live_admin(prefix, opts \\ [])

(macro)

Mount Beacon LiveAdmin routes to manage running sites in the cluster.

Examples

defmodule MyAppWeb.Router do
  use Phoenix.Router
  use Beacon.LiveAdmin.Router

  scope "/", MyAppWeb do
    pipe_through :browser
    beacon_live_admin "/admin", on_mount: [SomeHook]
  end
end

Or using AshAuthentication to protect the admin pages:

beacon_live_admin "/admin", AshAuthentication.Phoenix.LiveSession.opts(on_mount: [{MyAppWeb.LiveUserAuth, :live_user_required}])

Options

  • :name (required) atom() - register your instance with a unique name. Note that the name has to match the one used in your instance configuration.
  • :on_mount (optional) - an optional list of on_mount hooks passed to live_session. This will allow for authenticated routes, among other uses.
  • :session (optional) - an optional extra session map or MFA tuple to be merged with the Beacon.LiveAdmin session. Useful to authenticate the session using 3rd-party libs like AshAuthentication.

beacon_live_admin_path(conn_or_socket)

@spec beacon_live_admin_path(conn_or_socket()) :: String.t()

Generates the root path with the admin prefix.

Example

iex> Beacon.LiveAdmin.Router.beacon_live_admin_path(@socket)
"/my_admin"

beacon_live_admin_path(conn_or_socket, site, path, params \\ %{})

@spec beacon_live_admin_path(
  conn_or_socket(),
  Beacon.Types.Site.t(),
  String.t() | atom(),
  map() | keyword()
) :: String.t()

Generates a path with the proper admin prefix for a site.

Examples

iex> Beacon.LiveAdmin.Router.beacon_live_admin_path(@socket, :my_site, "/pages")
"/my_admin/my_site/pages"

iex> Beacon.LiveAdmin.Router.beacon_live_admin_path(@socket, :my_site, "/pages", status: :draft)
"/my_admin/my_site/pages?status=draft"

beacon_live_admin_static_path(file)

Generate the path to serve files in priv/static.

See the actual configuration in Beacon.LiveAdmin.Plug.

Example

iex> Beacon.LiveAdmin.Router.beacon_live_admin_static_path("/images/logo.webp")
"__beacon_live_admin_static__/images/logo.webp"