trepa-web/src/components/forms/LoginFormData.tsx
2024-07-01 21:58:06 +02:00

24 lines
656 B
TypeScript

import LoginForm, { type LoginFormValue } from "./LoginForm";
export default function LoginFormData() {
function handleOnFormSubmit(data: LoginFormValue) {
const searchParams = new URLSearchParams(window.location.search);
fetch("/api/accounts/login", {
method: "POST",
body: JSON.stringify(data),
credentials: "include",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
})
.then((res) => res.json())
.then((json) => {
window.location.href = searchParams.get("redirect") || "/home";
})
.catch((err) => console.log(err));
}
return <LoginForm onSubmit={handleOnFormSubmit} />;
}