From 28dd929927d2c7091a4a6fb3b1478a35505b0546 Mon Sep 17 00:00:00 2001
From: JBB0807 <104856796+JBB0807@users.noreply.github.com>
Date: Fri, 2 May 2025 15:07:05 -0700
Subject: [PATCH] working login for students and logout
---
src/pages/SignIn.jsx | 42 ++++++++++++++++++++++++++++++------------
src/pages/SignUp.jsx | 4 ++--
2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/src/pages/SignIn.jsx b/src/pages/SignIn.jsx
index 9976eb5..a404843 100644
--- a/src/pages/SignIn.jsx
+++ b/src/pages/SignIn.jsx
@@ -3,7 +3,7 @@ import "@fortawesome/fontawesome-free/css/all.min.css";
function SignInForm() {
const [state, setState] = React.useState({
- email: "",
+ assignmentID: "",
password: "",
});
const handleChange = (evt) => {
@@ -17,15 +17,33 @@ function SignInForm() {
const handleOnSubmit = (evt) => {
evt.preventDefault();
- const { email, password } = state;
- alert(`You are login with email: ${email} and password: ${password}`);
+ const { assignmentId, password } = state;
+ console.log(`You are loggind in with email: ${assignmentId} and password: ${password}`);
- for (const key in state) {
- setState({
- ...state,
- [key]: "",
+ console.log("Submitting login request with state:", state);
+ fetch("http://localhost:8080/auth/student/login", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(state),
+ credentials: "include",
+ })
+ .then((response) => {
+ console.log("Received response:", response);
+ if (!response.ok) {
+ throw new Error("Network response was not ok");
+ }
+ return response.json();
+ })
+ .then((data) => {
+ console.log("Success:", data);
+ window.location.href = "/";
+ })
+ .catch((error) => {
+ console.error("Error occurred during login:", error);
+ alert("Login failed!");
});
- }
};
return (
@@ -39,10 +57,10 @@ function SignInForm() {
*/}
{
evt.preventDefault();
- const { name, email, password } = state;
+ const { assignmentID, password } = state;
alert(
- `You are signed in with name: ${name} email: ${email} and password: ${password}`
+ `You are signed in with assignmentID: ${assignmentID} and password: ${password}`
);
for (const key in state) {