import { useState, useEffect } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { useAuth } from '../contexts/AuthContext'; import './LoginPage.css'; function LoginPage() { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(null); const { user, login, loading: authLoading } = useAuth(); const navigate = useNavigate(); const location = useLocation(); // Get the return URL from location state, default to home const from = (location.state as { from?: string })?.from || '/'; // Redirect if already logged in useEffect(() => { if (user && !authLoading) { navigate(from, { replace: true }); } }, [user, authLoading, navigate, from]); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!username.trim() || !password) { setError('Please enter both username and password'); return; } setIsSubmitting(true); setError(null); try { await login(username, password); navigate(from, { replace: true }); } catch (err) { setError(err instanceof Error ? err.message : 'Login failed. Please try again.'); } finally { setIsSubmitting(false); } } // Show loading while checking auth state if (authLoading) { return (
Checking session...
); } return (

Sign in to Orchard

Content-Addressable Storage

{error && (
{error}
)}
setUsername(e.target.value)} placeholder="Enter your username" autoComplete="username" autoFocus disabled={isSubmitting} />
setPassword(e.target.value)} placeholder="Enter your password" autoComplete="current-password" disabled={isSubmitting} />

Artifact storage and management system

); } export default LoginPage;