// app/auth/sign-up/page.tsx
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import SignUp from "./sign-up";
import { isJwtValid } from "@/lib/jwt";

export default async function SignUpPage({
    searchParams,
}: {
    searchParams?: Record<string, string | string[] | undefined>;
}) {
    const ck = await cookies();
    const at = ck.get("ma_at")?.value;
    if (isJwtValid(at)) redirect("/portal");

    const sp = searchParams ?? {};
    const nextParam = Array.isArray(sp.next) ? sp.next[0] : sp.next;
    const nextPath =
    nextParam && String(nextParam).startsWith("/") ? String(nextParam) : "/portal";

    return <SignUp nextPath={nextPath} />;
}
