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 { resolveClientIp } from "@/lib/client-ip"; 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 = resolveClientIp(await headers()); // Ticket write and online count run in parallel — the client page should // render as fast as possible since the player is waiting for the game. const [ticket, onlineCount] = await Promise.all([ issueSsoTicket(userId, hotelName, ip), 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 ( ); }