feat: login con idUsuario

This commit is contained in:
Nurfog committed 2026-09-09 16:20:24 -03:00
1 parent d1d8bf03ae
commit 57a83cd393
2 files changed
+14 -15

No files matched your search

+13 -14
View File
@@ -4,32 +4,31 @@ import { COOKIE, isAllowed, signSession, SESSION_MAX_AGE } from "@/lib/auth";
const API_URL =
process.env.NEXT_PUBLIC_API_URL || "https://api.devops.norteamericano.cl";
// Login IT: valida en el backend (sige_sam_v3.usuario, plano o SHA256)
// y exige que el correo esté en IT_USERS (allowlist).
// Login IT: USUARIO = idUsuario. Valida en el backend
// (sige_sam_v3.usuario, plano o SHA256) y exige que el email
// retornado esté en IT_USERS (allowlist).
export async function POST(req: NextRequest) {
try {
const { email, password } = await req.json();
const mail = String(email || "").trim().toLowerCase();
if (!mail || !password) {
const { idUsuario, email, password } = await req.json();
const id = String(idUsuario ?? email ?? "").trim();
if (!id || !password) {
return NextResponse.json({ error: "Faltan credenciales" }, { status: 400 });
}
if (!isAllowed(mail)) {
await new Promise((r) => setTimeout(r, 600));
return NextResponse.json({ error: "Credenciales inválidas" }, { status: 401 });
}
let ok = false;
let mail = "";
try {
const res = await fetch(`${API_URL}/api/Auth/it-login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email: mail, password: String(password) }),
body: JSON.stringify({ idUsuario: id, email: id, password: String(password) }),
cache: "no-store",
});
ok = res.ok;
if (!res.ok) throw new Error("backend");
const j = await res.json();
mail = String(j?.user?.email || "").trim().toLowerCase();
} catch {
ok = false;
mail = "";
}
if (!ok) {
if (!mail || !isAllowed(mail)) {
await new Promise((r) => setTimeout(r, 600));
return NextResponse.json({ error: "Credenciales inválidas" }, { status: 401 });
}
+1 -1
View File
@@ -19,7 +19,7 @@ function LoginForm() {
const res = await fetch("/api/auth", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email: rut, password: clave }),
body: JSON.stringify({ idUsuario: rut, password: clave }),
});
const j = await res.json();
if (!res.ok) throw new Error(j.error || `HTTP ${res.status}`);