import { useRef } from 'react'; export default function add() { const usernameInputRef = useRef(); const emailInputRef = useRef(); const passwordInputRef = useRef(); async function createUser(username, email, password) { const response = await fetch('/api/auth/signup', { method: 'POST', body: JSON.stringify({username, email, password}), headers: { 'Content-Type': 'application/json' } }); const data = await response.json(); if (!response.ok) { throw new Error(data.message || 'Something went wrong.'); } return data; } async function submitHandler(event) { event.preventDefault(); const enteredUsername = usernameInputRef.current.value; const enteredEmail = emailInputRef.current.value; const enteredPassword = passwordInputRef.current.value; // TODO: Add validation try { const result = await createUser(enteredUsername, enteredEmail, enteredPassword); console.log(result); } catch (error) { console.log(error); } } return (
); }