auth WIP 2

This commit is contained in:
2025-08-28 18:37:26 +03:00
parent 533da219b3
commit d23546d6e0
9 changed files with 97 additions and 35 deletions

View File

@ -2,24 +2,26 @@ import { useState } from "react";
import { useNavigate, useLocation } from "react-router-dom";
import useAuth from "../../auth/auth";
const Login = () => {
const { setToken: setAuth } = useAuth();
const { setToken } = useAuth();
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const navigate = useNavigate();
const location = useLocation();
const from = location.state?.from?.pathname || "/home";
const from = location.state?.from?.pathname || "/";
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
// TODO: request to API
if (username === "admin" && password === "1234") {
setAuth(true);
const token = "todo.jwt.token";
setToken(token);
navigate(from, { replace: true });
} else {
alert("Неверный логин или пароль");
alert("Wrong login or password");
}
};