import { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants"; import { Button } from "@documenso/ui"; import Logo from "./logo"; import { LockClosedIcon } from "@heroicons/react/20/solid"; import { signIn } from "next-auth/react"; import { FormProvider, useForm } from "react-hook-form"; import { toast } from "react-hot-toast"; interface LoginValues { email: string; password: string; totpCode: string; csrfToken: string; } export default function Login(props: any) { 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 = `${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: "Logging in...", success: "Login successful.", error: "Could not log in :/", }, { style: { minWidth: "200px", }, } ); if (!res) { setErrorMessage("Error"); toast.dismiss(); toast.error("Something went wrong."); } else if (!res.error) { // we're logged in, let's do a hard refresh to the original url router.push(callbackUrl); } 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

Forgot your password?
{props.allowSignup ? (

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

) : (

Like Documenso{" "} Hosted Documenso is here!

)}
{/* */} ); }