Skip to content

Commit 4f97e26

Browse files
committed
Fix Beacon admin routing — mount platform pages without site prefix
Beacon admin pages (/beacon, /beacon/users, etc.) were being mounted with /:site prefix like site-scoped pages, making them inaccessible. Now the router separates: - /beacon/* routes — mounted directly, no site prefix (platform-level) - All other routes — mounted with /:site prefix (site-scoped) PageLive mount handles pages without site param by using the first running site for the beacon_page context.
1 parent 121f9b5 commit 4f97e26

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

lib/beacon/live_admin/live/page_live.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ defmodule Beacon.LiveAdmin.PageLive do
3030
assign_mount(socket, site, page, sites, pages, params)
3131
end
3232

33+
# Beacon admin pages (no site param — platform-level)
34+
def mount(params, %{"pages" => pages} = session, socket) when not is_map_key(params, "site") do
35+
sites = Beacon.LiveAdmin.Cluster.running_sites()
36+
# Use the first running site for platform-level pages
37+
site = List.first(sites) || :beacon
38+
39+
current_url =
40+
Map.get(session, "beacon_live_admin_page_url") ||
41+
raise Beacon.LiveAdmin.PageNotFoundError, """
42+
failed to resolve Beacon.LiveAdmin page URL
43+
44+
You must add Beacon.LiveAdmin.Plug to the :browser pipeline that beacon_live_admin is piped through.
45+
"""
46+
47+
page = lookup_page!(socket, current_url)
48+
49+
assign_mount(socket, site, page, sites, pages, params)
50+
end
51+
3352
def mount(_params, _session, _socket) do
3453
raise Beacon.LiveAdmin.PageNotFoundError, """
3554
failed to resolve Beacon.LiveAdmin page URL

lib/beacon/live_admin/router.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,16 @@ defmodule Beacon.LiveAdmin.Router do
106106
live_session session_name, session_opts do
107107
live "/", Beacon.LiveAdmin.HomeLive, :index, as: :beacon_live_admin_home
108108

109-
for {path, page_module, live_action, _session} = page <- pages do
109+
# Beacon admin pages — platform-level, no site prefix
110+
for {path, page_module, live_action, _session} = page <- pages,
111+
String.starts_with?(path, "/beacon") do
112+
route_opts = Beacon.LiveAdmin.Router.__route_options__(opts, page)
113+
live path, Beacon.LiveAdmin.PageLive, live_action, route_opts
114+
end
115+
116+
# Site-scoped pages — prefixed with /:site
117+
for {path, page_module, live_action, _session} = page <- pages,
118+
not String.starts_with?(path, "/beacon") do
110119
route_opts = Beacon.LiveAdmin.Router.__route_options__(opts, page)
111120
path = "/:site#{path}"
112121
live path, Beacon.LiveAdmin.PageLive, live_action, route_opts

0 commit comments

Comments
 (0)