Adding login and registration base pages

This commit is contained in:
hz
2025-05-12 20:16:04 -07:00
parent 0aeea6fc17
commit a4a97414fc
97 changed files with 83502 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import config from "../config";
const Login = () => {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const navigate = useNavigate();
const handleLogin = async (e) => {
e.preventDefault();
const response = await fetch(`${config.API_BASE_URL}/api/Auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
});
if (response.ok) {
const data = await response.json();
// Save token etc.
console.log("Login successful:", data);
// Redirect or update state
} else {
alert("Login failed.");
}
};
const goToRegister = () => {
navigate("/register");
};
return (
<div>
<h2>Login</h2>
<form onSubmit={handleLogin}>
<input
type="text"
placeholder="Username"
value={username}
onChange={(e) => setUsername(e.target.value)}
required
/>
<br />
<input
type="password"
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
<br />
<button type="submit">Login</button>
<button
type="button"
onClick={goToRegister}
style={{ marginLeft: "10px" }}
>
Register
</button>
</form>
</div>
);
};
export default Login;