import { NextResponse } from 'next/server'; import { prisma } from '@/lib/prisma'; import { cookies } from 'next/headers'; import * as jose from 'jose'; export async function GET(request: Request) { try { const token = cookies().get('admin_token')?.value; if (!token) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } const secret = new TextEncoder().encode(process.env.JWT_SECRET || 'fallback-secret'); await jose.jwtVerify(token, secret); const contacts = await prisma.contactRequest.findMany({ orderBy: { createdAt: 'desc' }, }); return NextResponse.json({ contacts }); } catch (error) { console.error('Failed to load contacts:', error); return NextResponse.json({ error: 'Failed to load contacts' }, { status: 500 }); } }