'use client'; import { Button } from '@/components/ui/button'; import { Field, FieldError, FieldGroup, FieldLabel, } from '@/components/ui/field'; import { Input } from '@/components/ui/input'; import { deafultPasswordValidator } from '@/constants'; import { authClient } from '@/lib/auth-client'; import { zodResolver } from '@hookform/resolvers/zod'; import { Controller, useForm } from 'react-hook-form'; import { toast } from 'sonner'; import { z } from 'zod/v4'; const signUpSchema = z.object({ email: z.email(), password: deafultPasswordValidator(), name: z.string().min(1).max(100), }); export default function SignUp() { const form = useForm>({ resolver: zodResolver(signUpSchema), defaultValues: { email: '', password: '', }, }); async function onSubmit(values: z.infer) { const email = values.email; const password = values.password; const name = values.name; await authClient.signUp.email( { email, // user email address password, // user password -> min 8 characters by default name, callbackURL: '/dashboard', // A URL to redirect to after the user verifies their email (optional) }, { onRequest: (ctx) => { //show loading }, onSuccess: (ctx) => { //redirect to the dashboard or sign in page toast('Registered succesfully'); }, onError: (ctx) => { // display the error message toast(ctx.error.message); }, }, ); } return (
( Name {fieldState.invalid && } )} /> ( Email {fieldState.invalid && } )} /> ( Password {fieldState.invalid && } )} />
); }