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 (
{/* Header */} -
+
@@ -99,91 +63,92 @@ export const Login: React.FC = () => {
)} - {/* Simple Login Form */} -
-
- - setUsername(e.target.value)} - placeholder="Enter your TikTok email" - className="w-full bg-black/60 border-2 border-white/10 rounded-xl p-3.5 text-white text-sm focus:outline-none focus:border-cyan-500/50 placeholder:text-gray-600" - disabled={isLoading} - /> + {/* Instructions Toggle */} + -
- - setPassword(e.target.value)} - placeholder="Enter your password" - className="w-full bg-black/60 border-2 border-white/10 rounded-xl p-3.5 text-white text-sm focus:outline-none focus:border-cyan-500/50 placeholder:text-gray-600" - disabled={isLoading} - /> -
- - - - - {/* Info */} -

- Your credentials are used only to log into TikTok on the server. They are not stored. -

- - {/* Cookie Method - Alternative */} -
- - - {showCookieMethod && ( -
-

- If login doesn't work, you can paste TikTok cookies directly. -

-