"use client"; import { zodResolver } from "@hookform/resolvers/zod"; import { Icon } from "@iconify/react"; import { Button, Checkbox, Divider, Link } from "@nextui-org/react"; import { useRouter } from "next/navigation"; import { useEffect } from "react"; import { useFormState } from "react-dom"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { authenticate } from "@/actions"; import { Form, FormControl, FormField, FormMessage, } from "@/components/ui/form"; import { authFormSchema } from "@/types"; import { NotificationIcon, ProwlerExtended } from "../icons"; import { ThemeSwitch } from "../ThemeSwitch"; import { CustomInput } from "../ui/custom"; import { AuthButton } from "./AuthButton"; export const AuthForm = ({ type }: { type: string }) => { const formSchema = authFormSchema(type); const router = useRouter(); const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { email: "", password: "", }, }); const [state, dispatch] = useFormState(authenticate, undefined); useEffect(() => { if (state?.message === "Success") { router.push("/"); } }, [state]); const onSubmit = async (data: z.infer) => { // Do something with the form values // this will be type-safe and validated try { // Sign-up logic will be here. if (type === "sign-in") { dispatch({ email: data.email.toLowerCase(), password: data.password, }); } // if (type === "sign-up") { // const newUser = await signUp(data); // } } catch (error) { console.error(error); } }; return (
{/* Brand Logo and ThemeSwitch */}
{/* Testimonial */}

“ Open Cloud Security ”

{type === "sign-in" ? "Sign In" : "Sign Up"}

{type === "sign-up" && ( <> )} {type === "sign-in" && (
Remember me Forgot password?
)} {/* {isConfirmVisible ? ( ) : ( )} } label="Confirm Password" name="confirmPassword" placeholder="Confirm your password" type={isConfirmVisible ? "text" : "password"} variant="bordered" /> */} {type === "sign-up" && ( ( <> field.onChange(e.target.checked ? "true" : "false") } > I agree with the  Terms   and  Privacy Policy )} /> )} {state?.message === "Credentials error" && (

Incorrect email or password

)} {type === "sign-in" && ( <>

OR

)} {type === "sign-in" ? (

Need to create an account?  Sign Up

) : (

Already have an account?  Log In

)}
); };