From ef9cd8865b065b34cee11fe3fd7222046dc998af Mon Sep 17 00:00:00 2001 From: Dan Gleason Date: Thu, 29 Dec 2022 13:39:16 -0500 Subject: [PATCH] updated login page --- pages/signin.js | 53 ++++++++++++++++++++++++++----------------------- pages/signup.js | 36 +++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/pages/signin.js b/pages/signin.js index e73a29a..bb3ddc0 100644 --- a/pages/signin.js +++ b/pages/signin.js @@ -3,41 +3,43 @@ import axios from 'axios'; import { Link } from 'react-router-dom'; function LoginSignupForm() { - const [formData, setFormData] = useState({ - username: '', - password: '', - }); + const [username, setUsername] = useState(""); +const [password, setPassword] = useState(""); - const { username, password } = formData; - const onChange = e => - setFormData({ ...formData, [e.target.name]: e.target.value }); - const onSubmit = async e => { +const onSubmit = async e => { e.preventDefault(); - + const config = { headers: { 'Content-Type': 'application/json', }, }; - - const body = JSON.stringify({ username, password }); - + + const body = JSON.stringify({ + username: username, + password: password + }); + try { - // Use axios to send a POST request to the /login or /signup route - // depending on whether the user is trying to login or sign up - const res = await axios.post( - 'http://localhost:3000/login/signin', - body, - config + console.log("body: ", body); + // Use fetch to send a POST request to the /signup route + const res = await fetch( + 'http://localhost:3001/login/signup', + { + method: 'POST', + body: body, + headers: config.headers, + } ); - - console.log(res.data); + + console.log(await res.json()); } catch (err) { - console.error(err.response.data); + console.error(err); } }; + return ( <> @@ -67,7 +69,7 @@ function LoginSignupForm() {
-
onSubmit(e)}> +