"use client"; import { LegalAndSupportSettings } from "@zitadel/server"; import { useState } from "react"; import { Button, ButtonVariants } from "./Button"; import { TextInput } from "./Input"; import { PrivacyPolicyCheckboxes } from "./PrivacyPolicyCheckboxes"; import { FieldValues, useForm } from "react-hook-form"; import { useRouter } from "next/navigation"; import { Spinner } from "./Spinner"; import AuthenticationMethodRadio, { methods, } from "./AuthenticationMethodRadio"; type Inputs = | { firstname: string; lastname: string; email: string; } | FieldValues; type Props = { legal: LegalAndSupportSettings; }; export default function RegisterFormWithoutPassword({ legal }: Props) { const { register, handleSubmit, formState } = useForm({ mode: "onBlur", }); const [loading, setLoading] = useState(false); const [selected, setSelected] = useState(methods[0]); const router = useRouter(); async function submitAndRegister(values: Inputs) { setLoading(true); const res = await fetch("/registeruser", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ email: values.email, firstName: values.firstname, lastName: values.lastname, }), }); setLoading(false); if (!res.ok) { throw new Error("Failed to register user"); } return res.json(); } async function createSessionWithLoginName(loginName: string) { setLoading(true); const res = await fetch("/session", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ loginName: loginName, }), }); setLoading(false); if (!res.ok) { throw new Error("Failed to set user"); } return res.json(); } async function submitAndContinue( value: Inputs, withPassword: boolean = false ) { return withPassword ? router.push(`/register?` + new URLSearchParams(value)) : submitAndRegister(value).then((resp: any) => { createSessionWithLoginName(value.email).then(({ factors }) => { return router.push( `/passkey/add?` + new URLSearchParams({ loginName: factors.user.loginName }) ); }); }); } const { errors } = formState; const [tosAndPolicyAccepted, setTosAndPolicyAccepted] = useState(false); return (
{legal && ( )}

Select the method you would like to authenticate

); }