'use client'; import { useState } from 'react'; import { useApiKey } from '@/contexts/ApiKeyContext'; export default function SettingsPage() { const { apiKey, setApiKey, clearApiKey, isAuthenticated } = useApiKey(); const [inputValue, setInputValue] = useState(''); const [error, setError] = useState(''); const [success, setSuccess] = useState(''); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setSuccess(''); setIsLoading(true); if (!inputValue.trim()) { setError('API key is required'); setIsLoading(false); return; } // Test the API key by making a simple request try { const response = await fetch('/api/obsStatus', { headers: { 'x-api-key': inputValue.trim() } }); if (response.ok) { setApiKey(inputValue.trim()); setInputValue(''); setSuccess('API key saved successfully!'); } else { setError('Invalid API key'); } } catch { setError('Failed to validate API key'); } finally { setIsLoading(false); } }; const handleClearKey = () => { clearApiKey(); setInputValue(''); setError(''); setSuccess('API key cleared'); }; return (
API keys are required when accessing this application from external networks. The key is stored securely in your browser's local storage.