From 6b9023c87198c89e9715224dcef049dc6d980e60 Mon Sep 17 00:00:00 2001 From: DanielS Date: Wed, 15 Jul 2026 01:01:01 +0200 Subject: [PATCH] feat(wizard): connect license lookup panel to real lic server api endpoint --- .../wizard/license-lookup-panel.tsx | 12 ++++-- shop/lib/actions/licserver-config.ts | 39 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/shop/components/wizard/license-lookup-panel.tsx b/shop/components/wizard/license-lookup-panel.tsx index 7f08fb4..e8f4dab 100644 --- a/shop/components/wizard/license-lookup-panel.tsx +++ b/shop/components/wizard/license-lookup-panel.tsx @@ -21,6 +21,7 @@ import { } from 'lucide-react' import { Input } from '@/components/ui/input' import { Badge } from '@/components/ui/badge' +import { lookupLicenseFromLicServer } from '@/lib/actions/licserver-config' // ─── MOCK DATA (until real LicServer API is wired up) ─────────────────────── const MOCK_LICENSES: Record = { @@ -136,11 +137,14 @@ function fmt(dateStr: string) { }) } -// ─── MOCK LOOKUP (replace with real LicServer API call) ────────────────────── +// ─── LOOKUP (tries real LicServer API call, falls back to MOCK in dev) ────────────────────── async function lookupLicense(key: string): Promise { - // TODO: replace with → fetch(`/api/license-lookup?key=${encodeURIComponent(key)}`) - await new Promise(r => setTimeout(r, 800)) // simulate network latency - return MOCK_LICENSES[key.trim().toUpperCase()] ?? null + try { + return await lookupLicenseFromLicServer(key) + } catch (err) { + console.error('Lookup failed, falling back to mock details:', err) + return MOCK_LICENSES[key.trim().toUpperCase()] ?? null + } } // ─── MAIN COMPONENT ─────────────────────────────────────────────────────────── diff --git a/shop/lib/actions/licserver-config.ts b/shop/lib/actions/licserver-config.ts index c5928f8..7831184 100644 --- a/shop/lib/actions/licserver-config.ts +++ b/shop/lib/actions/licserver-config.ts @@ -110,3 +110,42 @@ export async function getLicServerConfigSystem(): Promise { api_key: data?.licserver_api_key || process.env.LICSERVER_API_KEY || null, } } + +export async function lookupLicenseFromLicServer(id: string) { + const supabase = await createClient() + const { data: { user } } = await supabase.auth.getUser() + if (!user) throw new Error('Nicht autorisiert.') + + const cfg = await getLicServerConfigSystem() + + if (!cfg.base_url || !cfg.api_key) { + throw new Error('LicServer ist nicht konfiguriert.') + } + + const res = await fetch(`${cfg.base_url}/v1/licenses/${encodeURIComponent(id.trim())}`, { + headers: { 'X-Api-Key': cfg.api_key, 'Accept': 'application/json' }, + signal: AbortSignal.timeout(5_000), + }) + + if (res.status === 404) return null + if (!res.ok) { + throw new Error(`Lizenzserver antwortete mit Fehler: HTTP ${res.status}`) + } + + const data = await res.json() + + return { + licenseKey: data.id, + status: 'active' as const, + product: data.productId || 'Unbekanntes Produkt', + edition: data.serialNumber ? `Seriennummer: ${data.serialNumber}` : 'Standard', + version: '1.0.0', + seats: 1, + customer: data.filename || 'Lizenz-Datei', + contact: '—', + issuedAt: '', + expiresAt: '', + maintenanceUntil: '', + modules: [], + } +}