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"; import { toast, Toaster } from "react-hot-toast"; import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants"; 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)) { if (process.env.NODE_ENV !== "production") { } callbackUrl = `${NEXT_PUBLIC_WEBAPP_URL}/${callbackUrl}`; } const onSubmit = async (values: LoginValues) => { setErrorMessage(null); const res = await toast.promise( signIn<"credentials">("credentials", { ...values, callbackUrl, redirect: false, }), { loading: "Loggin in...", success: "Login successful.", error: "Could not log in :/", }, { style: { minWidth: "200px", }, } ); if (!res) { setErrorMessage("error"); toast.dismiss(); toast.error("Something went wrong."); } // we're logged in! let's do a hard refresh to the desired url else if (!res.error) { router.push(callbackUrl); // toast.error("error"); } // fallback if error not found else { toast.dismiss(); if (res.status == 401) { toast.error("Invalid email or password."); } else { toast.error("Could not login."); } } }; return ( <>

Sign in to your account

Are you new here?{" "} Create a new Account

{/* */} ); }