'use client'; import { useState } from 'react'; import { InputWithLabel } from '@/components/forms/input-with-label'; import { Logo } from '@/components/logo'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; import { Button } from '@/components/ui/button'; import { Widget, WidgetBody } from '@/components/widget'; import { zodResolver } from '@hookform/resolvers/zod'; import { KeySquareIcon } from 'lucide-react'; import { signIn } from 'next-auth/react'; import Link from 'next/link'; import { usePathname, useRouter } from 'next/navigation'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; const validator = z.object({ email: z.string().email(), password: z.string().min(6), }); type IForm = z.infer; export default function Auth() { const form = useForm({ resolver: zodResolver(validator), }); const router = useRouter(); const pathname = usePathname(); const [state, setState] = useState(null); return (
{ const res = await signIn('credentials', { email: values.email, password: values.password, redirect: false, }).catch(() => { setState('Something went wrong. Please try again later'); }); if (res?.ok) { router.refresh(); } if (res?.status === 401) { setState('Wrong email or password. Please try again'); } })} className="flex flex-col gap-4" > {state !== null && ( Failed {state} )} No account?{' '} Sign up here!

Terms & conditions

); }