import React, { useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import { LogIn, Loader2 } from "lucide-react"; import { toast } from "sonner"; import { useAuth } from "@/contexts/AuthContext"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; const Login: React.FC = () => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const { login } = useAuth(); const navigate = useNavigate(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!email || !password) { toast.error("Please fill in email and password"); return; } setIsLoading(true); try { await login(email, password); toast.success("Logged in successfully"); navigate("/"); } catch (error: any) { toast.error(error.message || "Login failed"); } finally { setIsLoading(false); } }; return (
Ai
Sign In Login is for existing accounts only.
setEmail(e.target.value)} disabled={isLoading} required className="bg-background border-border" />
setPassword(e.target.value)} disabled={isLoading} required className="bg-background border-border" />
Need an account?{" "} Register
); }; export default Login;