2026-04-09 21:52:34 +02:00
|
|
|
import { Routes, Route, Navigate } from 'react-router';
|
2026-04-04 21:55:21 +02:00
|
|
|
import { LoginPage } from './auth/LoginPage';
|
|
|
|
|
import { CallbackPage } from './auth/CallbackPage';
|
|
|
|
|
import { ProtectedRoute } from './auth/ProtectedRoute';
|
2026-04-05 02:50:51 +02:00
|
|
|
import { OrgResolver } from './auth/OrgResolver';
|
2026-04-04 21:55:21 +02:00
|
|
|
import { Layout } from './components/Layout';
|
2026-04-09 21:52:34 +02:00
|
|
|
import { RequireScope } from './components/RequireScope';
|
2026-04-09 22:37:28 +02:00
|
|
|
import { useScopes } from './auth/useScopes';
|
2026-04-09 23:24:22 +02:00
|
|
|
import { useOrgStore } from './auth/useOrganization';
|
2026-04-09 21:52:34 +02:00
|
|
|
|
|
|
|
|
import { VendorTenantsPage } from './pages/vendor/VendorTenantsPage';
|
|
|
|
|
import { CreateTenantPage } from './pages/vendor/CreateTenantPage';
|
|
|
|
|
import { TenantDetailPage } from './pages/vendor/TenantDetailPage';
|
2026-04-10 13:07:18 +02:00
|
|
|
import { VendorAuditPage } from './pages/vendor/VendorAuditPage';
|
2026-04-09 21:52:34 +02:00
|
|
|
import { TenantDashboardPage } from './pages/tenant/TenantDashboardPage';
|
|
|
|
|
import { TenantLicensePage } from './pages/tenant/TenantLicensePage';
|
|
|
|
|
import { OidcConfigPage } from './pages/tenant/OidcConfigPage';
|
|
|
|
|
import { TeamPage } from './pages/tenant/TeamPage';
|
|
|
|
|
import { SettingsPage } from './pages/tenant/SettingsPage';
|
2026-04-10 13:07:18 +02:00
|
|
|
import { TenantAuditPage } from './pages/tenant/TenantAuditPage';
|
2026-04-04 21:55:21 +02:00
|
|
|
|
2026-04-09 22:37:28 +02:00
|
|
|
function LandingRedirect() {
|
|
|
|
|
const scopes = useScopes();
|
2026-04-09 23:24:22 +02:00
|
|
|
const { organizations, currentOrgId } = useOrgStore();
|
|
|
|
|
const currentOrg = organizations.find((o) => o.id === currentOrgId);
|
|
|
|
|
|
2026-04-09 23:39:12 +02:00
|
|
|
// Wait for scopes to be resolved — they're loaded async by OrgResolver.
|
|
|
|
|
// An empty set means "not yet loaded" (even viewer gets observe:read).
|
|
|
|
|
if (scopes.size === 0) {
|
|
|
|
|
return null; // OrgResolver is still fetching tokens
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 23:24:22 +02:00
|
|
|
// Vendor → vendor console
|
2026-04-09 22:37:28 +02:00
|
|
|
if (scopes.has('platform:admin')) {
|
|
|
|
|
return <Navigate to="/vendor/tenants" replace />;
|
|
|
|
|
}
|
2026-04-09 23:24:22 +02:00
|
|
|
// Tenant admin → tenant portal
|
|
|
|
|
if (scopes.has('tenant:manage')) {
|
|
|
|
|
return <Navigate to="/tenant" replace />;
|
|
|
|
|
}
|
|
|
|
|
// Regular user (operator/viewer) → server dashboard directly
|
|
|
|
|
const serverUrl = currentOrg?.slug ? `/t/${currentOrg.slug}/` : '/server/';
|
|
|
|
|
window.location.href = serverUrl;
|
|
|
|
|
return null;
|
2026-04-09 22:37:28 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-04 21:55:21 +02:00
|
|
|
export function AppRouter() {
|
|
|
|
|
return (
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route path="/login" element={<LoginPage />} />
|
|
|
|
|
<Route path="/callback" element={<CallbackPage />} />
|
2026-04-09 21:52:34 +02:00
|
|
|
<Route element={<ProtectedRoute />}>
|
|
|
|
|
<Route element={<OrgResolver />}>
|
|
|
|
|
<Route element={<Layout />}>
|
|
|
|
|
{/* Vendor console */}
|
|
|
|
|
<Route path="/vendor/tenants" element={
|
|
|
|
|
<RequireScope scope="platform:admin" fallback={<Navigate to="/tenant" replace />}>
|
|
|
|
|
<VendorTenantsPage />
|
|
|
|
|
</RequireScope>
|
|
|
|
|
} />
|
|
|
|
|
<Route path="/vendor/tenants/new" element={
|
|
|
|
|
<RequireScope scope="platform:admin" fallback={<Navigate to="/tenant" replace />}>
|
|
|
|
|
<CreateTenantPage />
|
|
|
|
|
</RequireScope>
|
|
|
|
|
} />
|
|
|
|
|
<Route path="/vendor/tenants/:id" element={
|
|
|
|
|
<RequireScope scope="platform:admin" fallback={<Navigate to="/tenant" replace />}>
|
|
|
|
|
<TenantDetailPage />
|
|
|
|
|
</RequireScope>
|
|
|
|
|
} />
|
2026-04-10 13:07:18 +02:00
|
|
|
<Route path="/vendor/audit" element={
|
|
|
|
|
<RequireScope scope="platform:admin" fallback={<Navigate to="/tenant" replace />}>
|
|
|
|
|
<VendorAuditPage />
|
|
|
|
|
</RequireScope>
|
|
|
|
|
} />
|
2026-04-09 21:52:34 +02:00
|
|
|
|
|
|
|
|
{/* Tenant portal */}
|
|
|
|
|
<Route path="/tenant" element={<TenantDashboardPage />} />
|
|
|
|
|
<Route path="/tenant/license" element={<TenantLicensePage />} />
|
|
|
|
|
<Route path="/tenant/oidc" element={<OidcConfigPage />} />
|
|
|
|
|
<Route path="/tenant/team" element={<TeamPage />} />
|
2026-04-10 13:07:18 +02:00
|
|
|
<Route path="/tenant/audit" element={<TenantAuditPage />} />
|
2026-04-09 21:52:34 +02:00
|
|
|
<Route path="/tenant/settings" element={<SettingsPage />} />
|
|
|
|
|
|
2026-04-09 22:37:28 +02:00
|
|
|
{/* Default redirect — vendor goes to /vendor/tenants, customer to /tenant */}
|
|
|
|
|
<Route index element={<LandingRedirect />} />
|
2026-04-09 21:52:34 +02:00
|
|
|
</Route>
|
|
|
|
|
</Route>
|
2026-04-04 21:55:21 +02:00
|
|
|
</Route>
|
|
|
|
|
</Routes>
|
|
|
|
|
);
|
|
|
|
|
}
|