import React, { useState, useEffect } from 'react'; import { GhostGridLogo } from './Header'; import { authFetch, saveSession } from '../lib/auth'; import { User } from '../types'; import { LogIn, Eye, EyeOff, AlertCircle } from 'lucide-react'; interface LoginPageProps { onLogin: (user: User) => void; onNavigateToRegister: () => void; authError?: string; } export default function LoginPage({ onLogin, onNavigateToRegister, authError }: LoginPageProps) { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(authError || ''); const [loading, setLoading] = useState(false); const [azureEnabled, setAzureEnabled] = useState(false); useEffect(() => { fetch('/api/auth/config') .then(r => r.json()) .then(d => setAzureEnabled(Boolean(d.azureEnabled))) .catch(() => {}); }, []); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { const res = await authFetch('/api/auth/login', { method: 'POST', body: JSON.stringify({ email, password }), }); const data = await res.json(); if (!res.ok) { setError(data.error || 'Login failed.'); return; } saveSession(data.token, data.user); onLogin(data.user); } catch { setError('Could not reach the server. Please try again.'); } finally { setLoading(false); } }; return (
BUILD AND CONTROL INVISIBLE INFRASTRUCTURE
Enter your credentials to access the platform.
No account yet?{' '}