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 (
{/* Logo & Brand */}

GhostGrid

BUILD AND CONTROL INVISIBLE INFRASTRUCTURE

A product by AirITSystems
{/* Login Card */}

Sign in

Enter your credentials to access the platform.

{error && (
{error}
)}
setEmail(e.target.value)} className="w-full bg-slate-900 border border-slate-700 rounded-lg px-3 py-2.5 text-sm text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500/50 transition-all" placeholder="" />
setPassword(e.target.value)} className="w-full bg-slate-900 border border-slate-700 rounded-lg px-3 py-2.5 pr-10 text-sm text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500/50 transition-all" placeholder="" />
{azureEnabled && ( <>
or
)}

No account yet?{' '}

); }