File size: 1,363 Bytes
c28c532
 
ddd2690
c28c532
 
 
ddd2690
c28c532
ddd2690
 
c28c532
ddd2690
c28c532
ddd2690
c28c532
 
 
 
ddd2690
 
 
 
c28c532
 
 
 
 
 
 
ddd2690
 
 
 
 
 
 
c28c532
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { NextRequest, NextResponse } from "next/server";

// POST /api/admin/auth — verify admin credentials (email + password)
export async function POST(request: NextRequest) {
  try {
    const body = await request.json();
    const { email, password } = body;

    const adminEmail = process.env.ADMIN_EMAIL || "imadmaalouf02@gmail.com";
    const adminPassword = process.env.ADMIN_PASSWORD || "ia-admin-2025";

    if (!email || !password) {
      return NextResponse.json(
        { error: "L'email et le mot de passe sont requis" },
        { status: 400 }
      );
    }

    // Normalize email for comparison
    const normalizedEmail = email.toLowerCase().trim();

    if (normalizedEmail === adminEmail.toLowerCase() && password === adminPassword) {
      return NextResponse.json({
        success: true,
        token: adminPassword,
        message: "Authentification réussie",
      });
    }

    if (normalizedEmail !== adminEmail.toLowerCase()) {
      return NextResponse.json(
        { error: "Email non autorisé" },
        { status: 401 }
      );
    }

    return NextResponse.json(
      { error: "Mot de passe incorrect" },
      { status: 401 }
    );
  } catch (error) {
    console.error("Admin auth failed:", error);
    return NextResponse.json(
      { error: "Erreur d'authentification" },
      { status: 500 }
    );
  }
}