"use client" import { getCsrfToken, signIn } from "next-auth/react" import { useTranslations } from "next-intl" import { useRouter } from "next/navigation" import { useEffect, useState } from "react" import { Loader } from "./loading/Loader" export function SignIn() { const t = useTranslations("SignIn") const [csrfToken, setCsrfToken] = useState("") const [loading, setLoading] = useState(false) const [errorState, setErrorState] = useState(false) const [successState, setSuccessState] = useState(false) const router = useRouter() useEffect(() => { async function loadProviders() { const csrf = await getCsrfToken() setCsrfToken(csrf) } loadProviders() }, []) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) const formData = new FormData(e.currentTarget) const password = formData.get("password") as string const res = await signIn("credentials", { password: password, redirect: false, }) if (res?.error) { console.log("login error") setErrorState(true) setSuccessState(false) } else { console.log("login success") setErrorState(false) setSuccessState(true) router.push("/") router.refresh() } setLoading(false) } return (
) }