/** * Login Form Component * Provides user authentication interface with JWT token support */ import React, { useState } from 'react'; import { useNavigate, Link } from 'react-router-dom'; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'; 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 { Eye, EyeOff, Lock, User, AlertCircle } from 'lucide-react'; import { useAuth } from '../../contexts/AuthContext'; interface LoginFormProps { onSuccess?: () => void; redirectTo?: string; } export const LoginForm: React.FC = ({ onSuccess, redirectTo = '/dashboard' }) => { const [formData, setFormData] = useState({ username: '', password: '', }); const [showPassword, setShowPassword] = useState(false); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const { login } = useAuth(); const navigate = useNavigate(); const handleInputChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setFormData(prev => ({ ...prev, [name]: value, })); // Clear error when user starts typing if (error) setError(''); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); setError(''); try { await login(formData.username, formData.password); if (onSuccess) { onSuccess(); } else { navigate(redirectTo); } } catch (err: any) { setError(err.message || 'Login failed. Please check your credentials.'); } finally { setIsLoading(false); } }; const togglePasswordVisibility = () => { setShowPassword(!showPassword); }; return (
Welcome to Hive

Sign in to your account to continue

{error && ( {error} )}

Need help?{' '} View documentation

{/* Development info */} {process.env.NODE_ENV === 'development' && (

Development Mode:
Default credentials: admin / admin123

)}
); }; export default LoginForm;