import { useState, useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { ShieldCheck, KeyRound, AlertTriangle } from 'lucide-react'; const STORAGE_KEY = 'fv_access_granted'; export function useAccessControl() { const [granted, setGranted] = useState(() => { return sessionStorage.getItem(STORAGE_KEY) === 'true'; }); const grant = () => { sessionStorage.setItem(STORAGE_KEY, 'true'); setGranted(true); }; return { granted, grant }; } interface SecretGateProps { onGranted: () => void; } export default function SecretGate({ onGranted }: SecretGateProps) { const [code, setCode] = useState(''); const [error, setError] = useState(false); const [errorMessage, setErrorMessage] = useState(''); const [shake, setShake] = useState(false); const [loading, setLoading] = useState(false); const inputRef = useRef(null); useEffect(() => { inputRef.current?.focus(); }, []); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(false); setErrorMessage(''); try { const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:8000'; const response = await fetch(`${apiUrl}/api/validate-code`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ code }), }); const data = await response.json(); if (response.ok && data.status === 'success') { onGranted(); } else { setError(true); setShake(true); setErrorMessage(data.detail || 'Invalid or expired code.'); setCode(''); setTimeout(() => setShake(false), 600); } } catch (err) { setError(true); setShake(true); setErrorMessage('Server connection failed.'); setTimeout(() => setShake(false), 600); } finally { setLoading(false); } }; return (
{/* Ambient orbs */}
{/* Header */}
Restricted Access

Enter Access Code

This platform is restricted to authorised personnel. Enter your secret access code to continue.

{/* Form */}
{ setCode(e.target.value); setError(false); }} placeholder="FV-ALPHA-101" autoComplete="off" disabled={loading} style={{ width: '100%', padding: '14px 18px', background: 'rgba(255,255,255,0.05)', border: error ? '1px solid rgba(239,68,68,0.6)' : '1px solid rgba(255,255,255,0.1)', borderRadius: 12, color: 'var(--text-1)', fontSize: '1rem', letterSpacing: '0.15em', outline: 'none', transition: 'border-color 0.2s', boxSizing: 'border-box', }} />
{error && ( {errorMessage} )}

Don't have an access code?{' '} Request access →

); }