redir fixes + 404 style fixes
This commit is contained in:
@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user