"use client"; import { useState } from "react"; import { Button, ButtonVariants } from "./Button"; import { TextInput } from "./Input"; import { useForm } from "react-hook-form"; import { useRouter } from "next/navigation"; import { Spinner } from "./Spinner"; import { ListAuthenticationMethodTypesResponse, AuthenticationMethodType, } from "@zitadel/server"; type Inputs = { loginName: string; }; export default function UsernameForm() { const { register, handleSubmit, formState } = useForm({ mode: "onBlur", }); const [loading, setLoading] = useState(false); async function submitUsernameAndGetAuthenticationMethods( values: Inputs ): Promise { setLoading(true); const res = await fetch("/methods", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ loginName: values.loginName, }), }); setLoading(false); if (!res.ok) { throw new Error("Failed to load authentication methods"); } return res.json(); } function submitUsernameAndContinue(value: Inputs): Promise { return submitUsernameAndGetAuthenticationMethods(value).then( ({ factors, sessionId, authMethodTypes }) => { console.log(factors, sessionId, authMethodTypes); if (authMethodTypes.length === 1) { } else { } } ); } const { errors } = formState; return (
{/* */}
); }