'use client'; import { useState, useEffect } from 'react'; import { bootstrapMasterKey } from '@/lib/actions/apiKeyActions'; import KeyDisplay from '@/components/admin/KeyDisplay'; import AdminFormInput from '@/components/admin/AdminFormInput'; import AdminButton from '@/components/admin/AdminButton'; import { NarrowSection } from '@/components/shared/NarrowSection'; const STORAGE_KEY = 'banatie_master_key'; export default function MasterKeyPage() { const [masterKey, setMasterKey] = useState(''); const [manualKey, setManualKey] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(''); // Load saved key from localStorage on mount useEffect(() => { const saved = localStorage.getItem(STORAGE_KEY); if (saved) { setMasterKey(saved); } }, []); const handleBootstrap = async () => { setLoading(true); setError(''); setSuccess(''); const result = await bootstrapMasterKey(); if (result.success && result.apiKey) { setMasterKey(result.apiKey); setSuccess('Master key generated successfully!'); } else { setError(result.error || 'Failed to bootstrap master key'); } setLoading(false); }; const handleSave = () => { if (masterKey) { localStorage.setItem(STORAGE_KEY, masterKey); setSuccess('Master key saved to localStorage!'); setTimeout(() => setSuccess(''), 3000); } }; const handleManualSave = () => { if (manualKey) { localStorage.setItem(STORAGE_KEY, manualKey); setMasterKey(manualKey); setManualKey(''); setSuccess('Master key saved to localStorage!'); setTimeout(() => setSuccess(''), 3000); } }; const handleClear = () => { localStorage.removeItem(STORAGE_KEY); setMasterKey(''); setSuccess('Master key cleared from localStorage'); setTimeout(() => setSuccess(''), 3000); }; return ( {/* Page Header */}

Master Key Management

Bootstrap your master key or manually configure it. This key is required to generate project API keys.

{/* Messages */} {error && (
{error}
)} {success && (
{success}
)} {/* Bootstrap Section */}

Bootstrap Master Key

Generate the first master key for your system. This only works if no keys exist yet.

{loading ? 'Generating...' : 'Generate Master Key'}
{/* Current Key Display */} {masterKey && (

Current Master Key

Save to LocalStorage Clear from LocalStorage
)} {/* Manual Entry Section */}

Manual Key Entry

Already have a master key? Enter it here to save it to localStorage.

Save Manual Key
); }