diff --git a/frontend/src/pages/LoginPage.jsx b/frontend/src/pages/LoginPage.jsx index dc29604..14672bc 100644 --- a/frontend/src/pages/LoginPage.jsx +++ b/frontend/src/pages/LoginPage.jsx @@ -1,29 +1,39 @@ import React, { useState } from "react"; -import { Button, Col, Container, Form, Row } from "react-bootstrap"; +import { Button, Col, Container, Form, Row, Alert} from "react-bootstrap"; import MyNavbar from "../components/MyNavbar"; import { makeRequest } from "../utils.ts"; const LoginPage = () => { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); + const [error, setError] = useState(null); - const sendLoginRequest = async () => { - // await makeRequest({ - // url: "http://localhost:5000/login", - // method: "POST", - // body: { username, password }, - // }) - // .then((resp) => resp.json()) - // .then((data) => { - // console.log(data); - // }); + const sendLoginRequest = async (e) => { + e.preventDefault(); + await makeRequest({ + url: "http://localhost:5000/login", + method: "POST", + body: { username, password }, + }) + .then((resp) => resp.json()) + .then((data) => { + if (data.error) { + setError(data); + return; + } + console.log(data); + window.location.href = "/"; + }); }; return ( + { error && ( + ERROR! {error.message} + )} -
+ Username