import { ok } from "../../../../lib/http";
import { getSession } from "../../../../lib/auth/session";
import { getPrisma } from "../../../../lib/db";

export const runtime = "nodejs";

export async function GET() {
  const session = await getSession();
  if (!session) return ok({ session: null });

  const prisma = await getPrisma();
  if (!prisma) return ok({ session });

  const user = await prisma.user.findUnique({ where: { id: session.sub } });
  return ok({
    session,
    user: user
      ? {
          firstName: user.firstName,
          lastName: user.lastName,
          avatarUrl: user.image,
          role: user.role,
          email: user.email,
        }
      : null,
  });
}
