import { Routes, Route, Navigate } from 'react-router';
import { LoginPage } from './auth/LoginPage';
import { CallbackPage } from './auth/CallbackPage';
import { ProtectedRoute } from './auth/ProtectedRoute';
import { OrgResolver } from './auth/OrgResolver';
import { Layout } from './components/Layout';
import { RequireScope } from './components/RequireScope';
import { useScopes } from './auth/useScopes';
import { useOrgStore } from './auth/useOrganization';
import { VendorTenantsPage } from './pages/vendor/VendorTenantsPage';
import { CreateTenantPage } from './pages/vendor/CreateTenantPage';
import { TenantDetailPage } from './pages/vendor/TenantDetailPage';
import { VendorAuditPage } from './pages/vendor/VendorAuditPage';
import { CertificatesPage } from './pages/vendor/CertificatesPage';
import { InfrastructurePage } from './pages/vendor/InfrastructurePage';
import { VendorMetricsPage } from './pages/vendor/VendorMetricsPage';
import { TenantDashboardPage } from './pages/tenant/TenantDashboardPage';
import { TenantLicensePage } from './pages/tenant/TenantLicensePage';
import { SsoPage } from './pages/tenant/SsoPage';
import { TeamPage } from './pages/tenant/TeamPage';
import { SettingsPage } from './pages/tenant/SettingsPage';
import { TenantAuditPage } from './pages/tenant/TenantAuditPage';
function LandingRedirect() {
const scopes = useScopes();
const { organizations, currentOrgId, scopesReady } = useOrgStore();
const currentOrg = organizations.find((o) => o.id === currentOrgId);
// Wait for scopes to be fully resolved by OrgResolver before redirecting.
if (!scopesReady) {
return null;
}
// Vendor → vendor console
if (scopes.has('platform:admin')) {
return ;
}
// Tenant admin → tenant portal
if (scopes.has('tenant:manage')) {
return ;
}
// Regular user (operator/viewer) → server dashboard directly
if (currentOrg?.slug) {
window.location.href = `/t/${currentOrg.slug}/`;
return null;
}
// No org resolved yet — stay on tenant portal
return ;
}
export function AppRouter() {
return (
} />
} />
}>
}>
}>
{/* Vendor console */}
}>
} />
}>
} />
}>
} />
}>
} />
}>
} />
}>
} />
}>
} />
{/* Tenant portal */}
} />
} />
} />
} />
} />
} />
{/* Default redirect — vendor goes to /vendor/tenants, customer to /tenant */}
} />
);
}