"use client" import { useForm } from "react-hook-form"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { toast } from "@/components/ui/use-toast"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { redirect } from "next/navigation"; import { loginSchema } from "./schema"; import { useRouter } from "next/navigation"; export default function LoginForm() { const router = useRouter() const form = useForm>({ resolver: zodResolver(loginSchema), }) const onSubmit = form.handleSubmit(async (data) => { // const res = await login(data) // if (res?.error) { // toast({ title: "Whoops!", description: res.error }) // form.reset() // } else { // toast({ title: "login successful" }) // } const res = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-type': 'application/json', }, body: JSON.stringify(data), }) if (res.status === 200) { toast({ title: "login successful!" }) router.push('/submission') } else { toast({ title: "login failed!" }) } }) return (
( Email Address )} > ( Password )} >
) }