Fix Nitro client launcher: read the nitro_path setting

The /client launcher read a non-existent `nitro_client_url` setting, so it
always fell through to "No client configured" and the client never launched.
Faithful to AtomCMS's NitroController + nitro.blade.php, build the launch URL
as {nitro_path}/index.html?sso=<ticket> plus the toolbar colour params, via a
shared buildNitroClientUrl helper. The Flash launcher's Nitro fallback used the
same dead key and is fixed too.
This commit is contained in:
Simo committed 2026-06-29 21:10:44 +02:00
1 parent 54ec99de6d
commit 56cd6fd058
4 files changed
+62 -26

No files matched your search

+11 -10
View File
@@ -3,6 +3,7 @@ import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { ContentCard, EmptyState } from "@/components/public/ui";
import { issueSsoTicket } from "@/lib/auth/sso-ticket";
import { buildNitroClientUrl } from "@/lib/services/clients";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { siteSettings } from "@/lib/services/site-settings";
@@ -14,17 +15,13 @@ export default async function FlashClientPage() {
if (!session?.user?.id) redirect("/login");
const userId = Number(session.user.id);
// The Flash client URL may be stored under either key depending on the
// AtomCMS settings seed — try both, then fall back to the Nitro URL so the
// launcher still issues a working SSO ticket.
const [hotelName, flashUrl, flashUrlAlt, nitroUrl] = await Promise.all([
// The Flash client base URL may be stored under either settings key.
const [hotelNameRaw, flashUrl, flashUrlAlt] = await Promise.all([
siteSettings.get("hotel_name", "Atom").catch(() => "Atom"),
siteSettings.get("flash_client_url", "").catch(() => ""),
siteSettings.get("client_flash_url", "").catch(() => ""),
siteSettings.get("nitro_client_url", "").catch(() => ""),
]);
const clientUrl = flashUrl || flashUrlAlt || nitroUrl || "";
const hotelName = hotelNameRaw ?? "Atom";
const hdrs = await headers();
const ip =
@@ -32,11 +29,15 @@ export default async function FlashClientPage() {
// Faithful to AtomCMS's client controllers: issue (and persist) the SSO ticket
// on the launcher render, then hand it to the Flash client.
const ticket = await issueSsoTicket(prisma, userId, hotelName ?? "Atom", ip);
const ticket = await issueSsoTicket(prisma, userId, hotelName, ip);
const src = clientUrl
? `${clientUrl}${clientUrl.includes("?") ? "&" : "?"}sso=${encodeURIComponent(ticket)}`
// Use a configured Flash base URL (with the SSO ticket appended); otherwise
// fall back to the Nitro client so the launcher still works.
const flashBase = flashUrl || flashUrlAlt || "";
const flashSrc = flashBase
? `${flashBase}${flashBase.includes("?") ? "&" : "?"}sso=${encodeURIComponent(ticket)}`
: "";
const src = flashSrc || (await buildNitroClientUrl(ticket));
return (
<main style={{ display: "grid", gap: "1.5rem" }}>
+11 -15
View File
@@ -3,6 +3,7 @@ import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { ContentCard, EmptyState } from "@/components/public/ui";
import { issueSsoTicket } from "@/lib/auth/sso-ticket";
import { buildNitroClientUrl } from "@/lib/services/clients";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { siteSettings } from "@/lib/services/site-settings";
@@ -14,28 +15,22 @@ export default async function ClientPage() {
if (!session?.user?.id) redirect("/login");
const userId = Number(session.user.id);
const [hotelName, clientUrl] = await Promise.all([
siteSettings.get("hotel_name", "Atom"),
siteSettings.get("nitro_client_url", ""),
]);
const hotelName = (await siteSettings.get("hotel_name", "Atom")) ?? "Atom";
const hdrs = await headers();
const ip =
hdrs.get("x-forwarded-for")?.split(",")[0]?.trim() ?? hdrs.get("x-real-ip") ?? "0.0.0.0";
// Faithful to AtomCMS's NitroController: issue (and persist) the SSO ticket on
// the launcher render, then hand it to the client.
const ticket = await issueSsoTicket(prisma, userId, hotelName ?? "Atom", ip);
const src = clientUrl
? `${clientUrl}${clientUrl.includes("?") ? "&" : "?"}sso=${encodeURIComponent(ticket)}`
: "";
// the launcher render, then hand it to the Nitro client at {nitro_path}.
const ticket = await issueSsoTicket(prisma, userId, hotelName, ip);
const src = await buildNitroClientUrl(ticket);
return (
<main style={{ display: "grid", gap: "1.5rem" }}>
<ContentCard
icon="🏨"
title={`Launching ${hotelName ?? "Atom"}…`}
title={`Launching ${hotelName}…`}
subtitle="Your single sign-on ticket is ready"
action={
<Link href="/client/flash" className="btn btn-outline">
@@ -49,14 +44,15 @@ export default async function ClientPage() {
<iframe
title="Hotel client"
src={src}
style={{ width: "100%", height: "80vh", border: 0, borderRadius: 10, display: "block" }}
style={{ width: "100%", height: "85vh", border: 0, borderRadius: 10, display: "block" }}
/>
</ContentCard>
) : (
<ContentCard icon="🔌" title="No client configured" subtitle="Set nitro_client_url in settings">
<ContentCard icon="🔌" title="No client configured" subtitle="Set nitro_path in settings">
<EmptyState icon="🔌">
No client URL configured (set <code>nitro_client_url</code> in settings). SSO ticket
issued for this session: <code>{ticket}</code>
No Nitro client configured — set <code>nitro_path</code> (e.g.{" "}
<code>/Nitro-V3/dist</code>) in the admin settings. SSO ticket issued for this session:{" "}
<code>{ticket}</code>
</EmptyState>
</ContentCard>
)}
+39
View File
@@ -0,0 +1,39 @@
import { siteSettings } from "./site-settings";
/**
* Builds the Nitro client launch URL, faithful to AtomCMS's NitroController +
* nitro.blade.php:
*
* {nitro_path}/index.html?sso={ticket}&toolbar_primary=…&toolbar_hover=…
* &toolbar_border=…&toolbar_text=…
*
* The client files are served by the web root at `nitro_path` (e.g.
* `/Nitro-V3/dist`). Returns "" when no `nitro_path` is configured.
*/
export async function buildNitroClientUrl(ticket: string): Promise<string> {
const [nitroPathRaw, tPrimary, tHover, tBorder, tText, bPrimary, bHover, bBorder, bText] =
await Promise.all([
siteSettings.get("nitro_path", ""),
siteSettings.get("toolbar_primary_color", ""),
siteSettings.get("toolbar_hover_color", ""),
siteSettings.get("toolbar_border_color", ""),
siteSettings.get("toolbar_text_color", ""),
siteSettings.get("button_primary_color", ""),
siteSettings.get("button_hover_color", ""),
siteSettings.get("button_border_color", ""),
siteSettings.get("button_text_color", ""),
]);
const nitroPath = (nitroPathRaw ?? "").trim().replace(/\/+$/, "");
if (!nitroPath) return "";
// Same fallbacks as the blade: toolbar_* color, else button_* color, else the
// atom defaults. URLSearchParams encodes "#" → "%23" so the query is valid.
const params = new URLSearchParams({ sso: ticket });
params.set("toolbar_primary", tPrimary || bPrimary || "#eeb425");
params.set("toolbar_hover", tHover || bHover || "#cf9d15");
params.set("toolbar_border", tBorder || bBorder || "#cf9d15");
params.set("toolbar_text", tText || bText || "#1a1a2e");
return `${nitroPath}/index.html?${params.toString()}`;
}
+1 -1
View File
@@ -6,7 +6,7 @@ const DEFAULTS: Record<string, string> = {
hotel_name: "Atom",
habbo_imaging_url: "https://www.habbo.com/habbo-imaging/avatarimage",
logo_url: "",
nitro_client_url: "",
nitro_path: "",
};
/**