diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index dd178cd..9db888a 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -4,71 +4,35 @@ import axios from 'axios'; import { API_BASE_URL } from '../config'; export const Login: React.FC = () => { - const [username, setUsername] = useState(''); - const [password, setPassword] = useState(''); + const [sessionId, setSessionId] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); - const [showCookieMethod, setShowCookieMethod] = useState(false); - const [cookies, setCookies] = useState(''); + const [showInstructions, setShowInstructions] = useState(true); const navigate = useNavigate(); - const handleLogin = async (e: React.FormEvent) => { - e.preventDefault(); - if (!username.trim() || !password.trim()) return; + const handleLogin = async () => { + if (!sessionId.trim()) return; setError(''); setIsLoading(true); try { - const res = await axios.post(`${API_BASE_URL}/auth/login`, { - username: username.trim(), - password: password.trim() - }); - - if (res.data.status === 'success') { - navigate('/'); - } else { - setError(res.data.message || 'Login failed. Please check your credentials.'); - } - } catch (err: any) { - const message = err.response?.data?.detail || err.response?.data?.message || 'Login failed. Please try again.'; - setError(message); - } finally { - setIsLoading(false); - } - }; - - const handleCookieLogin = async () => { - if (!cookies.trim()) return; - - setError(''); - setIsLoading(true); - - try { - // Try to parse as JSON - let jsonCreds; - try { - jsonCreds = JSON.parse(cookies); - } catch { - // If not JSON, wrap it as simple session format - jsonCreds = { - http: { - cookies: { sessionid: cookies.trim() } - } - }; - } - + // Send sessionid as credentials const res = await axios.post(`${API_BASE_URL}/auth/credentials`, { - credentials: jsonCreds + credentials: { + http: { + cookies: { sessionid: sessionId.trim() } + } + } }); if (res.data.status === 'success') { navigate('/'); } else { - setError(res.data.message || 'Failed to save cookies.'); + setError(res.data.message || 'Login failed.'); } } catch (err: any) { - setError(err.response?.data?.detail || 'Invalid cookie format.'); + setError(err.response?.data?.detail || 'Invalid session. Please try again.'); } finally { setIsLoading(false); } @@ -77,7 +41,7 @@ export const Login: React.FC = () => { return (