diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index caa3417..b27aa93 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import axios from 'axios'; import { API_BASE_URL } from '../config'; @@ -7,9 +7,53 @@ export const Login: React.FC = () => { const [sessionId, setSessionId] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); + const [loginStatus, setLoginStatus] = useState(''); const navigate = useNavigate(); - const handleConnect = async () => { + // Check if already authenticated + useEffect(() => { + checkAuth(); + }, []); + + const checkAuth = async () => { + try { + const res = await axios.get(`${API_BASE_URL}/auth/status`); + if (res.data.authenticated) { + navigate('/'); + } + } catch (err) { + // Not authenticated, stay on login + } + }; + + // Try browser login (opens TikTok in server's Playwright browser) + const handleBrowserLogin = async () => { + setError(''); + setIsLoading(true); + setLoginStatus('Opening TikTok login... Please wait'); + + try { + const res = await axios.post(`${API_BASE_URL}/auth/browser-login`, {}, { + timeout: 200000 // 3+ minutes timeout + }); + + if (res.data.status === 'success') { + setLoginStatus('Success! Redirecting...'); + setTimeout(() => navigate('/'), 1000); + } else { + setError(res.data.message || 'Login timed out. Please try the manual method.'); + setIsLoading(false); + setLoginStatus(''); + } + } catch (err: any) { + setError('Connection failed. Please try the manual method below.'); + setIsLoading(false); + setLoginStatus(''); + } + }; + + // Manual sessionid login + const handleManualLogin = async () => { if (!sessionId.trim()) return; setError(''); @@ -27,19 +71,15 @@ export const Login: React.FC = () => { if (res.data.status === 'success') { navigate('/'); } else { - setError('Connection failed. Please check your session ID.'); + setError('Invalid session ID. Please try again.'); } } catch (err: any) { - setError('Invalid session ID. Please try again.'); + setError('Connection failed. Please check your session ID.'); } finally { setIsLoading(false); } }; - const openTikTokLogin = () => { - window.open('https://www.tiktok.com/login', '_blank'); - }; - return (
- ⚠️ This requires a desktop/laptop computer with Chrome or Firefox + {/* Primary: Browser Login Button */} +
+ Opens TikTok login - complete the login and wait
Login to TikTok on desktop
- -Open DevTools & copy sessionid
-• Press F12 or Ctrl+Shift+I
-• Click Application tab
-• Click Cookies → tiktok.com
-• Find sessionid and copy its value
Paste here and connect
- setSessionId(e.target.value)} - placeholder="Paste sessionid value..." - className="w-full bg-black border-2 border-white/10 rounded-lg p-3 text-white text-sm font-mono focus:outline-none focus:border-pink-500/50 placeholder:text-gray-600" - disabled={isLoading} - /> -
+ If the button above doesn't work, paste your TikTok sessionid cookie:
+