68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import React, { useState } from "react";
|
|
import "./App.css";
|
|
import Header from "./Header";
|
|
|
|
function App() {
|
|
const [username, setUsername] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
|
|
try {
|
|
const response = await fetch("http://localhost:5002/api/login", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
username,
|
|
password,
|
|
}),
|
|
});
|
|
|
|
if (response.ok) {
|
|
console.log("Login successful");
|
|
// Handle successful login here
|
|
} else {
|
|
console.log("Login failed");
|
|
// Handle login error here
|
|
}
|
|
} catch (error) {
|
|
console.error("Login error:", error);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<form onSubmit={handleSubmit}>
|
|
<div>
|
|
<label htmlFor="username">Username:</label>
|
|
<input
|
|
type="text"
|
|
id="username"
|
|
name="username"
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
required
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="password">Password:</label>
|
|
<input
|
|
type="password"
|
|
id="password"
|
|
name="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
required
|
|
/>
|
|
</div>
|
|
<button type="submit">Login</button>
|
|
</form>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default App;
|