diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index d1eb4d6..ff58cfd 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -1,24 +1,23 @@ -import React, { useState } from 'react'; -import { useNavigate } from 'react-router-dom'; +import React, { useState, useEffect } from 'react'; +import { useNavigate, useSearchParams } from 'react-router-dom'; import axios from 'axios'; import { API_BASE_URL } from '../config'; export const Login: React.FC = () => { - const [sessionId, setSessionId] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); - const [step, setStep] = useState<1 | 2>(1); + const [searchParams] = useSearchParams(); const navigate = useNavigate(); - const openTikTokLogin = () => { - // Open TikTok login in new tab - window.open('https://www.tiktok.com/login', '_blank'); - setStep(2); - }; - - const handleConnect = async () => { - if (!sessionId.trim()) return; + // Check if we have a sessionid from URL (bookmarklet redirect) + useEffect(() => { + const sessionIdFromUrl = searchParams.get('sessionid'); + if (sessionIdFromUrl) { + handleAutoConnect(sessionIdFromUrl); + } + }, [searchParams]); + const handleAutoConnect = async (sessionId: string) => { setError(''); setIsLoading(true); @@ -26,7 +25,7 @@ export const Login: React.FC = () => { const res = await axios.post(`${API_BASE_URL}/auth/credentials`, { credentials: { http: { - cookies: { sessionid: sessionId.trim() } + cookies: { sessionid: sessionId } } } }); @@ -34,19 +33,39 @@ export const Login: React.FC = () => { if (res.data.status === 'success') { navigate('/'); } else { - setError(res.data.message || 'Connection failed.'); + setError('Connection failed. Please try again.'); + setIsLoading(false); } } catch (err: any) { - setError(err.response?.data?.detail || 'Invalid session ID. Please try again.'); - } finally { + setError('Invalid session. Please try again.'); setIsLoading(false); } }; + // Get the current app URL for bookmarklet redirect + const appUrl = window.location.origin; + + // Bookmarklet code - extracts sessionid and redirects back + const bookmarkletCode = `javascript:(function(){var c=document.cookie.split(';');var s='';for(var i=0;i { + navigator.clipboard.writeText(bookmarkletCode); + alert('Bookmarklet code copied! Create a new bookmark and paste this as the URL.'); + }; + + if (isLoading) { + return ( +
+
+

Connecting to TikTok...

+
+ ); + } + return (
{/* Header */} -
+
@@ -68,84 +87,59 @@ export const Login: React.FC = () => {
)} - {/* Step 1: Open TikTok */} -
-
-
1
- Login to TikTok -
- -

Opens in new tab - login with your account

-
+ {/* One-Time Setup (Desktop) */} +
+

+ 🖥️ Desktop Setup (One-Time) +

+
    +
  1. + 1. + Drag this button to your bookmarks bar: +
  2. +
- {/* Arrow */} -
-
-
- - {/* Step 2: Get Session ID */} -
-
-
2
- Copy your Session ID -
- -
-

After logging in on TikTok:

-
    -
  1. Press F12 (or right-click → Inspect)
  2. -
  3. Go to ApplicationCookies
  4. -
  5. Find sessionid and copy its value
  6. -
-
- - setSessionId(e.target.value)} - placeholder="Paste sessionid value here..." - className="w-full bg-black/60 border-2 border-white/10 rounded-xl p-4 text-white text-sm font-mono focus:outline-none focus:border-cyan-500/50 placeholder:text-gray-600 mb-4" - disabled={isLoading} - /> - - -
- - {/* Help */} - + + {/* How to Use */} +
+

+ 📱 How to Connect +

+
    +
  1. +
    1
    + Go to tiktok.com and login with your account +
  2. +
  3. +
    2
    + Click the "📎 Get PureStream" bookmark +
  4. +
  5. +
    3
    + You'll be automatically redirected and logged in! +
  6. +
+
+ + {/* Note */} +

+ The bookmarklet securely reads your TikTok session and connects it to PureStream. +