import { redirect } from "next/navigation"; import { listInstances } from "@tablestore/tablestore-agent-shared"; import { Sidebar } from "@/components/layout/sidebar"; import { SidebarMobile } from "@/components/layout/sidebar-mobile"; import { SidebarOffset } from "@/components/layout/sidebar-offset"; import { SkipToContent } from "@/components/layout/skip-to-content"; // The layout reads runtime state (TOML config, env vars) to decide whether // to redirect to onboarding. Must opt out of static rendering so the check // runs on every request rather than being cached from build time. export const dynamic = "force-dynamic"; /** * Whether any credential source (env vars, legacy [default] TOML section, or * a named instance) exists. When nothing is configured we redirect to the * onboarding flow so first-time users see the welcome card instead of a * broken dashboard. */ function hasUsableCredentials(): boolean { // A credential is either the AK/SK pair or an API Key; both need an // endpoint + instance name to be usable. const hasEnvCredential = (!!process.env.TABLESTORE_ACCESS_KEY_ID && !!process.env.TABLESTORE_ACCESS_KEY_SECRET) || !!process.env.TABLESTORE_API_KEY; const envConfigured = hasEnvCredential && !!process.env.TABLESTORE_ENDPOINT && !!process.env.TABLESTORE_INSTANCE_NAME; if (envConfigured) return true; try { const rows = listInstances(); // Named instances or the legacy [default] section both count. return rows.length > 0; } catch { return false; } } export default function DashboardLayout({ children, }: { children: React.ReactNode; }) { if (!hasUsableCredentials()) { redirect("/onboarding"); } return (
{children}
); }