import { NextRequest, NextResponse } from 'next/server'; import { buildAuthenticationOptions, finishAuthentication } from '@/lib/webauthn'; import { createSession } from '@/lib/session'; import { getConfiguredUsername } from '@/lib/auth'; // Öffentlich (kein Login): Optionen für die Anmeldung per Passkey. export async function GET() { try { return NextResponse.json(await buildAuthenticationOptions()); } catch (error) { console.error('GET /api/passkey/authenticate:', error); return NextResponse.json({ error: 'Serverfehler' }, { status: 500 }); } } // Öffentlich: Verifiziert die Anmelde-Antwort und erstellt bei Erfolg die Session. export async function POST(request: NextRequest) { try { const body = await request.json(); const result = await finishAuthentication(body?.response); if (!result.ok) return NextResponse.json({ error: result.error }, { status: 401 }); await createSession({ username: getConfiguredUsername(), isAuthenticated: true }); return NextResponse.json({ ok: true }); } catch (error) { console.error('POST /api/passkey/authenticate:', error); return NextResponse.json({ error: 'Serverfehler' }, { status: 500 }); } }