import { NextResponse } from "next/server"; import { getServerSession } from "next-auth"; import { authOptions } from "@/app/api/auth/[...nextauth]/route"; import { prisma } from "@/lib/prisma"; export async function GET() { const session = await getServerSession(authOptions); if (!session?.user?.email) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const user = await prisma.user.findUnique({ where: { email: session.user.email }, include: { documents: { orderBy: { createdAt: "desc" } }, }, }); if (!user) { return NextResponse.json({ error: "User not found" }, { status: 404 }); } return NextResponse.json({ documents: user.documents }); }