import { count, eq } from "drizzle-orm"; import { headers } from "next/headers"; import { redirect } from "next/navigation"; import { auth } from "@/lib/auth"; import { issueSsoTicket } from "@/lib/auth/sso-ticket"; import { cached } from "@/lib/cache"; import { db, User } from "@/lib/db"; import { resolveHotelName } from "@/lib/hotel-name"; import { siteSettings } from "@/lib/services/site-settings"; import { ClientView } from "./client-view"; export default async function ClientPage() { const session = await auth(); if (!session?.user?.id) redirect("/login"); const userId = Number(session.user.id); const [hotelName, clientUrl] = await Promise.all([ resolveHotelName(), siteSettings.get("nitro_client_url", ""), ]); const ip = (await headers()).get("x-real-client-ip") ?? "0.0.0.0"; const ticket = await issueSsoTicket(userId, hotelName, ip); const onlineCount = await cached("online_count", 10_000, async () => { const [row] = await db .select({ total: count() }) .from(User) .where(eq(User.online, "1")); return row?.total ?? 0; }).catch(() => 0); return ( ); }