Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,43 @@
import { LoaderFunctionArgs, redirect } from "react-router";
import { withMetrics } from "~/lib/metrics/ssr";
import { getAuthUserWithoutPasswordById as getUser, getTenantsForUser as getMyTenants } from "@toolctrl/db/auth-boundary.server";
import { getUserInfo } from "~/utils/session.server";
import { appPath } from "~/utils/app/CanonicalUrlUtils";
import { loadRequiredWebConfig } from "@toolctrl/config";
import { absoluteAdminPath } from "~/utils/app/CrossHostUrls";
// /app = Post-Login-Landing. KONSOLIDIERT auf EINEN Tenant-Auswahl-Screen: der frühere inline-Picker
// ("Konto auswählen") wurde durch Davids /select-tenant ersetzt. /app entscheidet nur noch den Flow:
// kein User -> /login · Admin -> Admin-Dashboard · genau 1 Tenant -> direkt ins Dashboard · sonst (0 oder
// >=2) -> /select-tenant (die eine Auswahl-UI in Davids Optik). Der Login-Redirect zielt für User ohne
// klaren Default-Tenant auf /app und landet damit auf /select-tenant.
export function sessionTenantDashboardPath(tenant: { slug?: string | null } | null) {
return tenant?.slug ? appPath({ tenantSlug: tenant.slug, path: "dashboard", mode: "host-aware" }) : "/";
}
export const loader = withMetrics("app-root", async ({ request }: LoaderFunctionArgs) => {
const userInfo = await getUserInfo(request);
const user = await getUser(userInfo.userId);
if (!user) {
throw redirect("/login");
}
const routing = loadRequiredWebConfig().routing;
// Admin -> Admin-Dashboard NUR wenn es einen GETRENNTEN Admin-Host gibt. Auf Single-Host-Setups
// (adminAppHost == webAppHost, z.B. fehlkonfiguriertes Staging ohne eigenen admin.-Host) zeigt der
// Redirect auf denselben Host und pingpongt mit der /dashboard-Route zurueck auf / -> Endlosschleife.
// In dem Fall in den normalen Tenant-Flow fallen (Profil-/Tenant-Auswahl statt Admin-Dashboard).
if (user.admin && routing.adminAppHost && routing.adminAppHost !== routing.webAppHost) {
throw redirect(absoluteAdminPath(routing, "dashboard"));
}
const myTenants = await getMyTenants(userInfo.userId);
if (myTenants.length === 1) {
throw redirect(sessionTenantDashboardPath(myTenants[0]));
}
throw redirect("/select-tenant");
});
// Der Loader leitet immer weiter; diese Komponente rendert nie (Fallback fuer die Route-Konvention).
export default function AppRoute() {
return null;
}