"use client"; import { useState, useEffect } from "react"; import { useSession } from "next-auth/react"; import { useRouter } from "next/navigation"; import Link from "next/link"; export default function WaitingPage() { const { data: session, status } = useSession(); const [huntActive, setHuntActive] = useState(false); const [loading, setLoading] = useState(true); const router = useRouter(); // Check hunt status at regular intervals useEffect(() => { const checkHuntStatus = async () => { try { const timestamp = Date.now(); const response = await fetch(`/api/hunt-status?t=${timestamp}`, { method: "GET", headers: { "Content-Type": "application/json", "Cache-Control": "no-store, no-cache, must-revalidate", Pragma: "no-cache", }, credentials: "include", }); if (response.ok) { const data = await response.json(); setHuntActive(data.active); // If hunt becomes active, redirect to map if (data.active) { router.push("/map"); } } setLoading(false); } catch (err) { console.error("Failed to check hunt status:", err); setLoading(false); } }; // Check status immediately checkHuntStatus(); // Set up regular polling const intervalId = setInterval(checkHuntStatus, 5000); // Clean up on unmount return () => clearInterval(intervalId); }, [router]); if (status === "unauthenticated") { router.push("/login"); return null; } if (loading) { return (
Loading...
The treasure hunt has not been activated by the organizers yet.
This page will automatically update when the hunt begins.