import { useState } from 'react' import { useNavigate, Link } from 'react-router-dom' import { useAuth } from '@/contexts/AuthContext' import { AuthLayout } from '@/components/layout/AuthLayout' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Alert, AlertDescription } from '@/components/ui/alert' import { Separator } from '@/components/ui/separator' import { Loader2, Mail, Lock, User, AlertCircle } from 'lucide-react' const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001' export function Register() { const navigate = useNavigate() const { register } = useAuth() const [name, setName] = useState('') const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState('') 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 { await register(email, password, name || undefined) // Registration successful, redirect to dashboard navigate('/') } catch (err) { const error = err as { response?: { data?: { message?: string } } } setError(error.response?.data?.message || 'Registration failed. Please try again.') } finally { setLoading(false) } } const handleGoogleSignup = () => { // Redirect to backend Google OAuth endpoint window.location.href = `${API_URL}/api/auth/google` } return (
{error && ( {error} )} {/* Google Sign Up */}
Or continue with email
{/* Email/Password Form */}
setName(e.target.value)} className="pl-10" disabled={loading} />
setEmail(e.target.value)} className="pl-10" required disabled={loading} />
setPassword(e.target.value)} className="pl-10" required disabled={loading} minLength={8} />

Must be at least 8 characters

setConfirmPassword(e.target.value)} className="pl-10" required disabled={loading} />

Already have an account?{' '} Sign in

) }