'use client'; import React, { useState } from 'react'; import { useApiKey } from '../contexts/ApiKeyContext'; interface ApiKeyPromptProps { show: boolean; onClose?: () => void; } export function ApiKeyPrompt({ show, onClose }: ApiKeyPromptProps) { const { setApiKey } = useApiKey(); const [inputValue, setInputValue] = useState(''); const [error, setError] = useState(''); if (!show) return null; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); if (!inputValue.trim()) { setError('API key is required'); 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(''); onClose?.(); } else { setError('Invalid API key'); } } catch { setError('Failed to validate API key'); } }; return (
This application requires an API key for access. Please enter your API key to continue.