'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import Link from 'next/link' import { authAPI } from '@/lib/api' import { saveAuth } from '@/lib/auth' export default function RegisterPage() { const router = useRouter() const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') if (password !== confirmPassword) { setError('Passwords do not match') return } if (password.length < 8) { setError('Password must be at least 8 characters') return } setLoading(true) try { const data = await authAPI.register(email, password) saveAuth(data.token, data.user) router.push('/dashboard') } catch (err: any) { const message = err.response?.data?.message || 'Failed to register' const details = err.response?.data?.details if (details && Array.isArray(details)) { setError(details.join(', ')) } else { setError(message) } } finally { setLoading(false) } } return (
Already have an account?{' '} Sign in