import React, { useState } from 'react'; import { useAuth } from '../../contexts/AuthContext'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card'; import { Label } from '../ui/label'; interface LoginFormProps { onSuccess?: () => void; onSwitchToRegister?: () => void; } export function LoginForm({ onSuccess, onSwitchToRegister }: LoginFormProps) { const { login, isLoading } = useAuth(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); try { await login(username, password); onSuccess?.(); } catch (err) { setError(err instanceof Error ? err.message : 'Login failed'); } }; return ( Login Enter your credentials to access your account
{error && (
{error}
)}
setUsername(e.target.value)} placeholder="Enter your username" required disabled={isLoading} />
setPassword(e.target.value)} placeholder="Enter your password" required disabled={isLoading} />
{onSwitchToRegister && (
Don't have an account?{' '}
)}
); }