import { useForm } from "react-hook-form" import { zodResolver } from "@hookform/resolvers/zod" import { registerSchema, type RegisterInput } from "@/lib/validations/auth" import { AuthService } from "@/services/auth" import { Button } from "@/components/ui/button" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { useState } from "react" import { Alert, AlertDescription } from "@/components/ui/alert" import { AlertCircle } from "lucide-react" import axios from "axios" interface RegisterFormProps { onSuccess: () => void onToggleMode: () => void } export function RegisterForm({ onSuccess, onToggleMode }: RegisterFormProps) { const [error, setError] = useState(null) const [isLoading, setIsLoading] = useState(false) const form = useForm({ resolver: zodResolver(registerSchema), defaultValues: { email: "", password: "", confirmPassword: "", }, }) async function onSubmit(values: RegisterInput) { setIsLoading(true) setError(null) try { await AuthService.register(values.email, values.password) // Since backend sets cookie on registration now, we can just call onSuccess onSuccess() } catch (err: unknown) { if (axios.isAxiosError(err)) { setError(err.response?.data?.detail || "Registration failed. Please try again.") } else { setError("An unexpected error occurred.") } } finally { setIsLoading(false) } } return ( Create an Account Enter your email and a password to get started.
{error && ( {error} )} ( Email )} /> ( Password )} /> ( Confirm Password )} />
Already have an account?{" "}
) }