src/app/api/mobile/check-user/route.ts

route·app·0.9 KB · 27 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

GET

Code source· typescript

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

export async function GET(req: NextRequest) {
  const { searchParams } = new URL(req.url);
  const identifier = searchParams.get("identifier")?.trim().toLowerCase();
  const identifierType = searchParams.get("identifierType");

  if (!identifier || !identifierType) {
    return NextResponse.json({ error: "Paramètres manquants" }, { status: 400 });
  }

  if (!["phone", "email"].includes(identifierType)) {
    return NextResponse.json({ error: "identifierType invalide" }, { status: 400 });
  }

  const client = await prisma.clientAccount.findFirst({
    where: identifierType === "email" ? { email: identifier } : { phone: identifier },
    select: { id: true, prenom: true, name: true },
  });

  return NextResponse.json({
    exists: !!client,
    prenom: client?.prenom ?? client?.name ?? null,
  });
}