39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { LanguageTypes } from "@/validations/mutual/language/validations";
|
|
|
|
export function loginHook(
|
|
startTransition: any,
|
|
data: any,
|
|
setError: any,
|
|
setJsonText: any,
|
|
Router: any,
|
|
lang: LanguageTypes
|
|
) {
|
|
try {
|
|
const sendData = { ...data };
|
|
startTransition(() => {
|
|
fetch("/api/login/email", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(sendData),
|
|
})
|
|
.then((response) => {
|
|
if (response.status === 200) {
|
|
response.json().then((data) => {
|
|
console.log("data", data); // setJsonText(JSON.stringify(data));
|
|
setTimeout(() => {
|
|
Router.push(`/auth/${lang}/select`);
|
|
}, 100);
|
|
});
|
|
} else {
|
|
response.json().then((data) => {
|
|
setError(data?.message);
|
|
});
|
|
}
|
|
})
|
|
.catch(() => {});
|
|
});
|
|
} catch (error) {
|
|
setError("An error occurred during login");
|
|
}
|
|
}
|