diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx new file mode 100644 index 0000000..502ecd8 --- /dev/null +++ b/frontend/src/pages/Login.tsx @@ -0,0 +1,92 @@ +import React, { useState } from 'react'; +import { useAuth } from '../contexts/AuthContext'; +import { useNavigate } from 'react-router-dom'; + +const Login: React.FC = () => { + const [username, setUsername] = useState(''); + const [password, setPassword] = useState(''); + const [error, setError] = useState(''); + const [isLoading, setIsLoading] = useState(false); + const { login } = useAuth(); + const navigate = useNavigate(); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setError(''); + setIsLoading(true); + + try { + await login(username, password); + navigate('/dashboard'); + } catch (err: any) { + setError(err.response?.data?.detail || 'Invalid username or password'); + } finally { + setIsLoading(false); + } + }; + + return ( +
+
+
+

Family Hub

+

Welcome back! Please sign in.

+
+ +
+ {error && ( +
+ {error} +
+ )} + +
+ + setUsername(e.target.value)} + className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" + placeholder="Enter your username" + required + autoComplete="username" + /> +
+ +
+ + setPassword(e.target.value)} + className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" + placeholder="Enter your password" + required + autoComplete="current-password" + /> +
+ + +
+ +
+

Default password: password123

+
+
+
+ ); +}; + +export default Login;