import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import { verifyToken } from "@/lib/auth";
import AchievementsClient from "./AchievementsClient";

export default async function AchievementsPage() {
  const cookieStore = await cookies();
  const token = cookieStore.get("nw_token")?.value;

  if (!token) redirect("/");

  let userId: string;
  try {
    userId = await verifyToken(token);
  } catch {
    redirect("/");
  }

  return <AchievementsClient initialUserId={userId} />;
}
