import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";
import { getApiUser } from "@/lib/apiAuth";
export async function GET(req: NextRequest) {
  const apiUser = await getApiUser(req);
  
  if (!apiUser) {
    return NextResponse.json({ error: "No session" }, { status: 401 });
  }

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

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