'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 (

Settings

{/* API Key Section */}

API Key Authentication

API keys are required when accessing this application from external networks. The key is stored securely in your browser's local storage.

{/* Current Status */}

Current Status

{isAuthenticated ? ( <>
Authenticated ) : ( <>
No API key set )}
{isAuthenticated && ( )}
{/* API Key Form */}
setInputValue(e.target.value)} className="w-full text-white focus:outline-none focus:ring-2 focus:ring-blue transition-all" style={{ padding: '12px 24px', background: 'rgba(7, 54, 66, 0.4)', backdropFilter: 'blur(10px)', border: '1px solid rgba(88, 110, 117, 0.3)', borderRadius: '12px', fontSize: '16px' }} placeholder="Enter your API key" />
{error && (

{error}

)} {success && (

{success}

)}
{/* Information Section */}

ℹ️ Information

  • API keys are only required for external network access
  • Local network access bypasses authentication automatically
  • Keys are validated against the server before saving
  • Your API key is stored locally and never transmitted unnecessarily
); }