This commit is contained in:
2025-08-27 18:57:12 +03:00
parent bb4603628c
commit 533da219b3
25 changed files with 3995 additions and 0 deletions

56
src/pages/login/login.tsx Normal file
View File

@ -0,0 +1,56 @@
import { useState } from "react";
import { useNavigate, useLocation } from "react-router-dom";
import useAuth from "../../auth/auth";
const Login = () => {
const { setToken: setAuth } = useAuth();
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const navigate = useNavigate();
const location = useLocation();
const from = location.state?.from?.pathname || "/home";
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
// TODO: request to API
if (username === "admin" && password === "1234") {
setAuth(true);
navigate(from, { replace: true });
} else {
alert("Неверный логин или пароль");
}
};
return (
<div style={{ padding: "20px" }}>
<h2>Login</h2>
<form onSubmit={handleSubmit}>
<div>
<label>Username:</label>
<input
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
required
/>
</div>
<div>
<label>Password:</label>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
</div>
<button type="submit" style={{ marginTop: "10px" }}>
Login
</button>
</form>
</div>
);
};
export default Login;