import { NextResponse } from "next/server";
import { getSession } from "@/lib/auth";

export async function GET() {
  try {
    const user = await getSession();

    if (!user) {
      return NextResponse.json(
        {
          success: false,
          authenticated: false,
          user: null,
          message: "Utilisateur non connecté.",
        },
        {
          status: 401,
        }
      );
    }

    return NextResponse.json({
      success: true,
      authenticated: true,
      user,
    });
  } catch (error) {
    console.error(
      "Erreur récupération session :",
      error
    );

    return NextResponse.json(
      {
        success: false,
        authenticated: false,
        user: null,
        message:
          "Impossible de récupérer la session.",
      },
      {
        status: 500,
      }
    );
  }
}