0792ac3767
Deploy / deploy (push) Successful in 6m52s
Cliente now picks a jefe mecánico after choosing the service so the calendar shows that specific jefe's availability. Each jefe has its own configurable parallel slot capacity (replacing the global SLOTS_PARALELOS = 5). Admins manage jefes from /admin/jefes; jefes log in to /jefe to see their daily agenda. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { crearSesionJefe } from "@/lib/auth-admin";
|
|
import bcrypt from "bcryptjs";
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const { email, password } = await req.json();
|
|
if (!email || !password)
|
|
return NextResponse.json({ error: "Credenciales requeridas" }, { status: 400 });
|
|
|
|
const jefe = await prisma.jefeMecanico.findUnique({
|
|
where: { email: String(email).toLowerCase().trim() },
|
|
});
|
|
if (!jefe || !jefe.activo)
|
|
return NextResponse.json({ error: "Credenciales incorrectas" }, { status: 401 });
|
|
|
|
const ok = await bcrypt.compare(password, jefe.passwordHash);
|
|
if (!ok) return NextResponse.json({ error: "Credenciales incorrectas" }, { status: 401 });
|
|
|
|
const jwt = await crearSesionJefe(jefe.id);
|
|
|
|
const response = NextResponse.json({ ok: true, jefe: { id: jefe.id, nombre: jefe.nombre } });
|
|
response.cookies.set("jefe_session", jwt, {
|
|
httpOnly: true,
|
|
secure: process.env.NODE_ENV === "production",
|
|
sameSite: "lax",
|
|
maxAge: 60 * 60 * 8,
|
|
path: "/",
|
|
});
|
|
return response;
|
|
}
|