"use client"; import { useUserStore } from "../store/user-store"; import { endpoints } from "../api/config"; import { authorize, isResponseOk } from "../api/api-utils"; import { useRouter } from "next/navigation"; import { useState, useEffect } from "react"; export default function LoginPage() { const userStore = useUserStore(); const router = useRouter(); const [authData, setAuthData] = useState({ email: "", password: "" }); useEffect(() => { if (userStore.isAuth) { router.push("/profile"); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const handleInput = (e) => { setAuthData({ ...authData, [e.target.name]: e.target.value }); }; const handleSubmit = async (e) => { e.preventDefault(); const userData = await authorize(endpoints.user.auth, authData); if (isResponseOk(userData)) { userStore.login( userData, userData.profileToken.token, userData.profile.id, ); } }; useEffect(() => { let timer; if (userStore.user) { timer = setTimeout(() => { router.push("/profile"); }, 1000); } return () => clearTimeout(timer); // eslint-disable-next-line react-hooks/exhaustive-deps }, [userStore.user]); return (