"use client"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useToast } from "@/components/ui/use-toast"; import { useForm } from "react-hook-form"; import * as z from "zod"; const authSchema = z.object({ email: z.string().email("Please enter a valid email"), password: z.string().min(8, "Password must be at least 8 characters"), }); export default function Auth() { const { push } = useRouter(); const { toast } = useToast(); const form = useForm>({ resolver: zodResolver(authSchema), defaultValues: { email: "", password: "", }, }); async function handleSignup(values: z.infer) { try { const res = await fetch("/auth/signup", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(values), }); const { error, message } = await res.json(); if (error) { toast({ variant: "destructive", title: "Uh oh! Something went wrong.", description: error, }); throw new Error(error); } else if (message) { toast({ title: "Check your email!", description: message, }); } } catch (error) { console.error(error); } } async function handleLogin(values: z.infer) { try { const res = await fetch("/auth/login", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(values), }); const { error } = await res.json(); if (error) { toast({ variant: "destructive", title: "Uh oh! Something went wrong.", description: error.message, }); throw new Error(error); } push("/"); } catch (error) { console.error(error); } } return (
Login Signup Login to your account Enter your email and password below to login.
( Email )} /> ( Password )} />
Create your account Enter your email and password below to create an account.
( Email )} /> ( Password )} />
); }