redir fixes + 404 style fixes

This commit is contained in:
2025-09-12 10:34:02 +03:00
parent 999b83d7e1
commit 09f4079b9e
3 changed files with 12 additions and 5 deletions

View File

@ -13,14 +13,15 @@ const Login = () => {
const { setToken } = useAuth();
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const navigate = useNavigate();
const location = useLocation();
const searchPath = new URLSearchParams(location.search);
const redirectPath = searchPath.get('to') || "/";
const [usernameEmpty, setUsernameEmpty] = useState(false);
const [passwordEmpty, setPasswordEmpty] = useState(false);
const from = location.state?.from?.pathname || "/";
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
@ -35,7 +36,7 @@ const Login = () => {
if ((username === "admin" && password === "1234") || (username === "a" && password === "a")) {
const token = "todo.jwt.token";
setToken(token);
navigate(from, { replace: true });
navigate(redirectPath, { replace: true });
} else {
toast.error("Wrong login or password");
}