'use client'; import { zodResolver } from '@hookform/resolvers/zod'; import { Loader } from 'lucide-react'; import { signIn } from 'next-auth/react'; import { useForm } from 'react-hook-form'; import { FcGoogle } from 'react-icons/fc'; import { z } from 'zod'; import { cn } from '@documenso/ui/lib/utils'; import { Button } from '@documenso/ui/primitives/button'; import { Input } from '@documenso/ui/primitives/input'; import { Label } from '@documenso/ui/primitives/label'; import { useToast } from '@documenso/ui/primitives/use-toast'; export const ZSignInFormSchema = z.object({ email: z.string().email().min(1), password: z.string().min(1), }); export type TSignInFormSchema = z.infer; export type SignInFormProps = { className?: string; }; export const SignInForm = ({ className }: SignInFormProps) => { const { toast } = useToast(); const { register, handleSubmit, formState: { errors, isSubmitting }, } = useForm({ values: { email: '', password: '', }, resolver: zodResolver(ZSignInFormSchema), }); const onFormSubmit = async ({ email, password }: TSignInFormSchema) => { try { await signIn('credentials', { email, password, callbackUrl: '/documents', }).catch((err) => { console.error(err); }); // throw new Error('Not implemented'); } catch (err) { toast({ title: 'An unknown error occurred', description: 'We encountered an unknown error while attempting to sign you In. Please try again later.', }); } }; const onSignInWithGoogleClick = async () => { try { await signIn('google', { callbackUrl: '/dashboard' }); // throw new Error('Not implemented'); } catch (err) { toast({ title: 'An unknown error occurred', description: 'We encountered an unknown error while attempting to sign you In. Please try again later.', variant: 'destructive', }); } }; return (
{ e.preventDefault(); handleSubmit(onFormSubmit)(); }} >
{errors.email && {errors.email.message}}
{errors.password && ( {errors.password.message} )}
Or continue with
); };