import React, { useState, useEffect, useRef } from 'react'; import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'; import { initLocalEngine, routeInference } from '../utils/inferenceRouter'; import HCaptcha from '@hcaptcha/react-hcaptcha'; import { supabase, useAuth, GATEWAY_URL, LEMON_CHECKOUT_URL } from '../context'; export default function SettingsKeysSection({ user }) { const [keys, setKeys] = useState([]); const [loading, setLoading] = useState(true); const fetchKeys = async () => { try { const res = await fetch(`https://opticparse-python-sg.onrender.com/gateway/keys/${user.id}`); const data = await res.json(); setKeys(data.keys || []); } catch (e) { console.error(e); } setLoading(false); }; useEffect(() => { if (user) fetchKeys(); }, [user]); const handleGenerate = async () => { if (keys.length >= 3) return alert("Maximum of 3 active keys allowed."); try { const res = await fetch('https://opticparse-python-sg.onrender.com/gateway/keys/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ user_id: user.id }) }); const data = await res.json(); alert(`IMPORTANT! Save this key, it will not be shown again: ${data.api_key}`); fetchKeys(); } catch (e) { console.error(e); alert("Failed to generate key"); } }; const handleRevoke = async (prefix) => { if (!confirm(`Are you sure you want to revoke key ending in ${prefix}?`)) return; try { await fetch(`https://opticparse-python-sg.onrender.com/gateway/keys/${user.id}/${prefix}`, { method: 'DELETE' }); fetchKeys(); } catch (e) { console.error(e); } }; return (

Active API Keys ({keys.length}/3)

You can generate up to 3 active API keys to separate your Live and Test environments.

{loading ? (
Loading keys...
) : ( {keys.map((k, i) => ( ))}
Prefix Created At Actions
op_live_••••••••{k.key_prefix} {new Date(k.created_at).toLocaleString()}
)} {keys.length < 3 && ( )}
); }