27 lines
966 B
TypeScript
27 lines
966 B
TypeScript
import { cookies } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
import LandingPage from "@/components/landing-page";
|
|
|
|
export default async function Home() {
|
|
const session = (await cookies()).get("foundry_session")?.value;
|
|
let authenticated = false;
|
|
if (session) {
|
|
const origin = process.env.FOUNDRY_API_ORIGIN || "https://api.foundry.entroia.com";
|
|
const project = process.env.NEXT_PUBLIC_FOUNDRY_PROJECT || "endoleap";
|
|
try {
|
|
const response = await fetch(`${origin}/projects/${encodeURIComponent(project)}/profile`, {
|
|
headers: { Authorization: `Bearer ${session}` },
|
|
cache: "no-store",
|
|
redirect: "manual",
|
|
signal: AbortSignal.timeout(15000),
|
|
});
|
|
authenticated = response.ok;
|
|
await response.body?.cancel();
|
|
} catch {
|
|
// An unverified session must not hide the public landing page.
|
|
}
|
|
}
|
|
if (authenticated) redirect("/dashboard");
|
|
return <LandingPage />;
|
|
}
|