import { LockClosedIcon } from "@heroicons/react/20/solid"; import Link from "next/link"; import { FormProvider, SubmitHandler, useForm } from "react-hook-form"; import Logo from "./logo"; import { getCsrfToken, signIn } from "next-auth/react"; import { ErrorCode } from "@documenso/lib/auth"; import { useState } from "react"; import { useRouter } from "next/router"; interface LoginValues { email: string; password: string; totpCode: string; csrfToken: string; } export default function Login() { const router = useRouter(); const methods = useForm(); const { register, formState } = methods; const [errorMessage, setErrorMessage] = useState(null); let callbackUrl = typeof router.query?.callbackUrl === "string" ? router.query.callbackUrl : ""; // If not absolute URL, make it absolute if (!/^https?:\/\//.test(callbackUrl)) { callbackUrl = `http://localhost:3000/${callbackUrl}`; } const onSubmit = async (values: LoginValues) => { setErrorMessage(null); const res = await signIn<"credentials">("credentials", { ...values, callbackUrl, redirect: false, }); if (!res) setErrorMessage("error"); // we're logged in! let's do a hard refresh to the desired url else if (!res.error) router.push(callbackUrl); // fallback if error not found else setErrorMessage("something_went_wrong"); }; return ( <>

Sign in to your account

Or{" "} create a new Account

); }