diff --git a/client/pages/login.tsx b/client/pages/login.tsx index a17f735..ca91c68 100644 --- a/client/pages/login.tsx +++ b/client/pages/login.tsx @@ -1,9 +1,40 @@ -import React from 'react'; +import React, { useState, FormEvent, ChangeEvent } from 'react'; import Image from 'next/image'; function Login() { + const [formData, setFormData] = useState({ + email: '', + password: '', + }); + + const handleSubmit = async (event: FormEvent) => { + event.preventDefault(); + + try { + const response = await fetch('http://localhost:3001/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: formData.email, + password: formData.password + }) + }); + + const data = await response.json() + console.log(data) + } catch (error) { + console.error('Error while login', error) + } + }; + + const handleChange = (event: ChangeEvent) => { + setFormData({... formData, [event.target.name]: event.target.value}) + } + return ( -
+
@@ -24,6 +55,9 @@ function Login() { className="text-black w-full rounded-sm p-2 text-xs" type="email" placeholder="Email" + name="email" + value={formData.email} + onChange={handleChange} />
@@ -31,6 +65,9 @@ function Login() { className="text-black w-full rounded-sm p-2 text-xs" type="password" placeholder="Password" + name="password" + value={formData.password} + onChange={handleChange} />
diff --git a/client/pages/signup.tsx b/client/pages/signup.tsx index 3fd6ee8..68bc626 100644 --- a/client/pages/signup.tsx +++ b/client/pages/signup.tsx @@ -1,7 +1,7 @@ import React, { useState, FormEvent, ChangeEvent } from 'react'; import Image from 'next/image'; -interface FormData { +export interface FormData { fname: string; lname: string; email: string; @@ -16,8 +16,8 @@ function SignUp() { password: '', }); - const handleSubmit = async (e: FormEvent) => { - e.preventDefault(); + const handleSubmit = async (event: FormEvent) => { + event.preventDefault(); try { const response = await fetch('http://localhost:3001/signup', { @@ -41,8 +41,8 @@ function SignUp() { } }; - const handleChange = (e: ChangeEvent) => { - setFormData({ ...formData, [e.target.name]: e.target.value }); + const handleChange = (event: ChangeEvent) => { + setFormData({ ...formData, [event.target.name]: event.target.value }); }; return (