import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import { db } from "@/lib/db";

export async function GET() {
  const session = await getServerSession(authOptions);
  
  if (!session) {
    return NextResponse.json({ error: "No session" }, { status: 401 });
  }

  const userId = (session.user as any).id;
  
  // بررسی وجود کاربر در دیتابیس
  const user = await db.user.findUnique({ 
    where: { id: userId },
    select: { id: true, email: true, name: true, role: true }
  });

  return NextResponse.json({
    session: {
      user: session.user,
      userId: userId,
    },
    userInDb: user,
    exists: !!user
  });
}
