import { cookies } from "next/headers"; import { prisma } from "./prisma"; import type { App } from "./generated/prisma/client"; const COOKIE_NAME = "active-app"; export async function getActiveApp(): Promise { const cookieStore = await cookies(); const slug = cookieStore.get(COOKIE_NAME)?.value; if (slug) { const app = await prisma.app.findUnique({ where: { slug } }); if (app) return app; } // Default to first app return prisma.app.findFirst({ orderBy: { createdAt: "asc" } }); } export async function getActiveAppId(): Promise { const app = await getActiveApp(); return app?.id ?? null; }