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

export default async function ProfilePage() {
  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 <ProfileClient initialUserId={userId} />;
}
