import React, { useState } from 'react'; import { Link, useNavigate, useLocation } from 'react-router-dom'; import { Mail, Lock, User, ArrowRight, Eye, EyeOff } from 'lucide-react'; import { Button } from '../components/ui/button'; import { Input } from '../components/ui/input'; import { Label } from '../components/ui/label'; import { Separator } from '../components/ui/separator'; import { useAuth } from '../context/AuthContext'; import { toast } from 'sonner'; const Login = () => { const navigate = useNavigate(); const location = useLocation(); const { login, register } = useAuth(); const [isRegister, setIsRegister] = useState(false); const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const [formData, setFormData] = useState({ name: '', email: '', password: '' }); const from = location.state?.from?.pathname || '/'; const handleSubmit = async (e) => { e.preventDefault(); setLoading(true); try { if (isRegister) { await register(formData.name, formData.email, formData.password); toast.success('Account created successfully!'); } else { await login(formData.email, formData.password); toast.success('Welcome back!'); } navigate(from, { replace: true }); } catch (error) { toast.error(error.response?.data?.detail || 'Authentication failed'); } finally { setLoading(false); } }; return (
{isRegister ? 'Enter your details to get started' : 'Sign in to your account to continue' }
{isRegister ? 'Already have an account?' : "Don't have an account?"}{' '}