import { NextRequest, NextResponse } from "next/server";
import prisma from "@/lib/db";
import { getSession } from "@/lib/auth";

export async function GET() {
    const session = await getSession();
    if (!session) return NextResponse.json({ error: "Non autorisé" }, { status: 401 });

    try {
        const subscribers = await (prisma as any).subscriber.findMany({
            orderBy: { createdAt: "desc" }
        });
        return NextResponse.json(subscribers);
    } catch {
        return NextResponse.json({ error: "Erreur serveur" }, { status: 500 });
    }
}
