import Head from 'next/head'; import {useRouter} from "next/router"; import {signIn} from 'next-auth/client' import ErrorAlert from "../../components/ui/alerts/Error"; import {useState} from "react"; import {UsernameInput} from "../../components/ui/UsernameInput"; import prisma from "../../lib/prisma"; export default function Signup(props) { const router = useRouter(); const [ hasErrors, setHasErrors ] = useState(false); const [ errorMessage, setErrorMessage ] = useState(''); const handleErrors = async (resp) => { if (!resp.ok) { const err = await resp.json(); throw new Error(err.message); } } const signUp = (e) => { e.preventDefault(); if (e.target.password.value !== e.target.passwordcheck.value) { throw new Error("Password mismatch"); } const email: string = e.target.email.value; const password: string = e.target.password.value; fetch('/api/auth/signup', { body: JSON.stringify({ username: e.target.username.value, password, email, }), headers: { 'Content-Type': 'application/json', }, method: 'POST' } ) .then(handleErrors) .then( () => signIn('Calendso', { callbackUrl: (router.query.callbackUrl || '') as string }) ) .catch( (err) => { setHasErrors(true); setErrorMessage(err.message); }); }; return (