Files
PeerNotes/frontend/src/screens/Login.tsx

40 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-03-24 18:02:40 -04:00
import { Link } from "react-router-dom"
import "../styles/Login.css"
2024-04-11 02:34:32 -04:00
import { FormEvent } from "react";
2024-03-24 18:02:40 -04:00
export default function Login() {
2024-04-11 02:34:32 -04:00
function handleSubmit(e: FormEvent) {
e.preventDefault();
const formData = new FormData(e.target as HTMLFormElement);
const username = formData.get('username');
const password = formData.get('password');
fetch('http://localhost:8000/api/login/', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
})
.catch((error) => {
console.error('Error:', error);
});
}
2024-03-24 18:02:40 -04:00
return (
<main>
2024-04-11 02:34:32 -04:00
<form className="login-container" onSubmit={handleSubmit}>
2024-03-24 18:02:40 -04:00
<h1>Login</h1>
2024-04-11 01:07:07 -04:00
<div className="form-input">
2024-03-24 18:02:40 -04:00
<label htmlFor="username">Username</label>
<input type="text" name="username" id="username" />
2024-04-11 01:07:07 -04:00
</div>
<div className="form-input">
2024-03-24 18:02:40 -04:00
<label htmlFor="password">Password</label>
<input type="password" name="password" id="password" />
</div>
2024-04-11 01:07:07 -04:00
<button className="submit-button">Login</button>
2024-03-24 18:02:40 -04:00
<p>or <Link to="/signup">Sign up</Link></p>
</form>
</main>
);
}