diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 1eee111..8574678 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -15,6 +15,7 @@ const App = () => { }); const [systemInfo, setSystemInfo] = useState(null); const [usageStats, setUsageStats] = useState(null); + const [authStatus, setAuthStatus] = useState(null); const [loading, setLoading] = useState(false); const [activeView, setActiveView] = useState('tasks'); // 'tasks' | 'dashboard' @@ -23,10 +24,12 @@ const App = () => { fetchTasks(); fetchSystemInfo(); fetchUsageStats(); + fetchAuthStatus(); const interval = setInterval(() => { fetchTasks(); fetchSystemInfo(); fetchUsageStats(); + fetchAuthStatus(); }, 10000); return () => clearInterval(interval); }, []); @@ -61,6 +64,38 @@ const App = () => { } }; + const fetchAuthStatus = async () => { + try { + const response = await fetch('/api/auth/status'); + const data = await response.json(); + setAuthStatus(data); + } catch (error) { + console.error('Error fetching auth status:', error); + } + }; + + const handleLogin = async () => { + try { + const response = await fetch('/api/auth/login', { method: 'POST' }); + const data = await response.json(); + setAuthStatus(prev => ({ ...prev, ...data })); + if (data.auth_url) { + window.open(data.auth_url, '_blank'); + } + } catch (error) { + console.error('Error initiating login:', error); + } + }; + + const handleLogout = async () => { + try { + await fetch('/api/auth/logout', { method: 'POST' }); + fetchAuthStatus(); + } catch (error) { + console.error('Error logging out:', error); + } + }; + const handleCreateTask = async (e) => { e.preventDefault(); setLoading(true); @@ -137,6 +172,15 @@ const App = () => { +