feat(wizard): connect license lookup panel to real lic server api endpoint
All checks were successful
Staging Build / build (push) Successful in 2m48s

This commit is contained in:
DanielS
2026-07-15 01:01:01 +02:00
parent f783a98392
commit 6b9023c871
2 changed files with 47 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ import {
} from 'lucide-react' } from 'lucide-react'
import { Input } from '@/components/ui/input' import { Input } from '@/components/ui/input'
import { Badge } from '@/components/ui/badge' import { Badge } from '@/components/ui/badge'
import { lookupLicenseFromLicServer } from '@/lib/actions/licserver-config'
// ─── MOCK DATA (until real LicServer API is wired up) ─────────────────────── // ─── MOCK DATA (until real LicServer API is wired up) ───────────────────────
const MOCK_LICENSES: Record<string, LicenseInfo> = { const MOCK_LICENSES: Record<string, LicenseInfo> = {
@@ -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<LicenseInfo | null> { async function lookupLicense(key: string): Promise<LicenseInfo | null> {
// TODO: replace with → fetch(`/api/license-lookup?key=${encodeURIComponent(key)}`) try {
await new Promise(r => setTimeout(r, 800)) // simulate network latency return await lookupLicenseFromLicServer(key)
return MOCK_LICENSES[key.trim().toUpperCase()] ?? null } catch (err) {
console.error('Lookup failed, falling back to mock details:', err)
return MOCK_LICENSES[key.trim().toUpperCase()] ?? null
}
} }
// ─── MAIN COMPONENT ─────────────────────────────────────────────────────────── // ─── MAIN COMPONENT ───────────────────────────────────────────────────────────

View File

@@ -110,3 +110,42 @@ export async function getLicServerConfigSystem(): Promise<LicServerConfig> {
api_key: data?.licserver_api_key || process.env.LICSERVER_API_KEY || null, 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: [],
}
}