"use client"; import { useState, useEffect } from "react"; import { useUserStore } from "#/store/auth"; import { setJWT } from "#/api/utils"; import { useRouter } from "next/navigation"; export function LoginPage() { const [login, setLogin] = useState(""); const [password, setPassword] = useState(""); const [remember, setRemember]: any = useState(false); const userStore = useUserStore(); const router = useRouter(); function submit(e) { e.preventDefault(); fetch("/api/profile/login", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ login: login, password: password, }), }) .then((response) => { if (response.ok) { return response.json(); } else { alert("Ошибка получения пользователя."); } }) .then((data) => { if (data.profileToken) { userStore.login(data.profile, data.profileToken.token); if (remember) { setJWT(data.profile.id, data.profileToken.token); } router.push("/"); } else { alert("Неверные данные."); } }); } useEffect(() => { if (userStore.user) { router.push("/"); } }, [userStore.user]); return (

Вход в аккаунт Anixart

setLogin(e.target.value)} required={true} />
setPassword(e.target.value)} />
setRemember(e.target.checked)} />
); }