import { NextResponse } from "next/server";
import { cookies } from "next/headers";
import { createRouteHandlerClient } from "@supabase/auth-helpers-nextjs";

export async function GET() {
  try {
    const supabase = createRouteHandlerClient({ cookies });
    const { data: { session } } = await supabase.auth.getSession();
    
    if (!session) {
      return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
    }

    // Vérifier dans user_metadata si l'utilisateur a un mot de passe
    const hasPassword = !!session.user.user_metadata?.hasPassword;
    
    return NextResponse.json({ hasPassword });
  } catch (e: any) {
    return NextResponse.json({ error: e?.message || "Erreur interne" }, { status: 500 });
  }
}