import { hasPasskeysForLogin } from "@/app/auth-actions";
import { getSession } from "@/lib/auth";
import { redirect } from "next/navigation";
import AuthForm from "./auth-form";

type SearchParams = { next?: string };

export default async function AuthPage({
  searchParams,
}: {
  searchParams: Promise<SearchParams>;
}) {
  const session = await getSession();
  if (session) {
    const dest = (await searchParams).next ?? "/";
    redirect(dest);
  }
  const passkeysAvailable = await hasPasskeysForLogin();
  const next = (await searchParams).next ?? "/";
  return <AuthForm passkeysAvailable={passkeysAvailable} next={next} />;
}

export const dynamic = "force-dynamic";
