import { cookies } from "next/headers"; import { redirect } from "next/navigation"; import Layout from "../components/Layout"; async function getAuthState() { const baseUrl = process.env.INTERNAL_API_URL || process.env.NEXT_PUBLIC_API_BASE_URL || "http://127.0.0.1:18000"; const cookieStore = await cookies(); const sessionCookie = cookieStore.get("ai_chat_session"); if (!sessionCookie) return null; try { const res = await fetch(`${baseUrl}/api/auth/me`, { headers: { Cookie: `${sessionCookie.name}=${sessionCookie.value}` }, cache: "no-store" }); if (!res.ok) return null; return await res.json(); } catch { return null; } } async function getChats() { const baseUrl = process.env.INTERNAL_API_URL || process.env.NEXT_PUBLIC_API_BASE_URL || "http://127.0.0.1:18000"; const cookieStore = await cookies(); const sessionCookie = cookieStore.get("ai_chat_session"); if (!sessionCookie) return []; try { const res = await fetch(`${baseUrl}/api/chats`, { headers: { Cookie: `${sessionCookie.name}=${sessionCookie.value}` }, cache: "no-store" }); if (!res.ok) return []; return await res.json(); } catch { return []; } } export default async function Home() { const auth = await getAuthState(); if (!auth) { redirect("/login"); } const chats = await getChats(); return (
Чем я могу помочь?
Выберите чат в меню слева или создайте новый.
); }