src/app/api/auth/client/verifier/route.ts

route·app·1.2 KB · 35 lignes· Voir l'itinéraire
Annotation non disponible

Lance npm run annotate (nécessite ANTHROPIC_API_KEY dans .env.local) pour générer une annotation française par Claude Haiku 4.5.

1 export

POST

Code source· typescript

import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma/client";
import { captureError } from "@/lib/sentry";

export async function POST(req: NextRequest) {
  try {
    const body = await req.json();
    // Accepte 'identifier' (spec mobile) et 'identifiant' (ancien format web)
    const raw: string = body.identifier ?? body.identifiant;
    if (!raw) return NextResponse.json({ error: "Identifiant requis" }, { status: 400 });

    const identifier = raw.trim().toLowerCase();
    const isEmail = identifier.includes("@");

    const client = await prisma.clientAccount.findFirst({
      where: isEmail ? { email: identifier } : { phone: raw.trim() },
      select: { id: true, motDePasseHash: true },
    });

    return NextResponse.json({
      exists: !!client,
      hasPassword: !!client?.motDePasseHash,
      // Champs legacy pour compatibilité web
      existe: !!client,
      aMotDePasse: !!client?.motDePasseHash,
    });
  } catch (error) {
    captureError(error, {
      route: "/api/auth/client/verifier",
    });
    console.error("verifier error:", error);
    return NextResponse.json({ error: "Erreur serveur" }, { status: 500 });
  }
}