Merge branch 'main' into homepage-2nd-sprint
This commit is contained in:
commit
eb9e055287
5 changed files with 45 additions and 35 deletions
|
|
@ -1,9 +1,11 @@
|
|||
import React from "react";
|
||||
import "@fortawesome/fontawesome-free/css/all.min.css";
|
||||
|
||||
const authUrl = import.meta.env.VITE_AUTH_URL;
|
||||
|
||||
function SignInForm() {
|
||||
const [state, setState] = React.useState({
|
||||
email: "",
|
||||
assignmentID: "",
|
||||
password: "",
|
||||
});
|
||||
const handleChange = (evt) => {
|
||||
|
|
@ -17,15 +19,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(`${authUrl}/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 +59,10 @@ function SignInForm() {
|
|||
</div> */}
|
||||
|
||||
<input
|
||||
type="email"
|
||||
placeholder="Student Name"
|
||||
name="email"
|
||||
value={state.email}
|
||||
type="assignmentId"
|
||||
placeholder="Assignment ID"
|
||||
name="assignmentId"
|
||||
value={state.assignmentId}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
<input
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ function SignUpForm() {
|
|||
const handleOnSubmit = (evt) => {
|
||||
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) {
|
||||
|
|
@ -34,7 +34,7 @@ function SignUpForm() {
|
|||
|
||||
const googleAuth = () => {
|
||||
|
||||
window.open(authUrl, "_self");
|
||||
window.open(`${authUrl}/auth/google`, "_self");
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue