"use client"; import { Suspense, useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; function LoginForm() { const router = useRouter(); const searchParams = useSearchParams(); const next = searchParams.get("next") || "/dashboard"; const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); // #region agent log function debugLog(hypothesisId: string, message: string, data: Record) { fetch("http://localhost:7701/ingest/5073259c-ddcc-441a-a087-e13a2cf7ac9e", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "ca90b5", }, body: JSON.stringify({ sessionId: "ca90b5", runId: "login-debug-01", hypothesisId, location: "frontend/app/tela_login/page.tsx:debugLog", message, data, timestamp: Date.now(), }), }).catch(() => {}); } // #endregion async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(""); if (!username.trim() || !password.trim()) { setError("Informe usuário e senha."); return; } setLoading(true); try { // #region agent log debugLog("H4", "login_submit_start", { endpoint: "/api/api/auth/login/", next, usernameLength: username.trim().length, }); // #endregion const res = await fetch("/api/api/auth/login/", { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", body: JSON.stringify({ username: username.trim(), password, next }), }); const data = await res.json().catch(() => ({})); // #region agent log debugLog("H5", "login_submit_response_body", { status: res.status, ok: res.ok, success: (data as { success?: boolean }).success, hasSuccessKey: Object.prototype.hasOwnProperty.call(data, "success"), redirect: (data as { redirect?: string })?.redirect || null, message: (data as { message?: string })?.message || null, }); debugLog("H1_H3", "login_submit_response", { status: res.status, ok: res.ok, redirect: (data as { redirect?: string })?.redirect || null, message: (data as { message?: string })?.message || null, }); // #endregion if (!res.ok) { setError(data.message || "Erro ao autenticar. Tente novamente."); return; } if (data.success && data.redirect) { router.push(data.redirect); } else { router.push("/dashboard"); } } catch { // #region agent log debugLog("H2", "login_submit_fetch_exception", { apiBaseHint: "proxied_by_next_api_route", }); // #endregion setError("Erro de conexão. Verifique se o backend está rodando."); } finally { setLoading(false); } } return (
{/* Painel esquerdo - visual */}
PROD

SGMP

Sistema de Gestão e Movimentações de Pessoas

{/* Painel direito - formulário */}

Bem-vindo

Insira suas credenciais para acessar.

{error && (
{error}
)}
setUsername(e.target.value)} placeholder="Matrícula Winthor" required autoFocus className="w-full px-4 py-3 border border-slate-200 rounded-lg text-base focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-colors" />
setPassword(e.target.value)} placeholder="Senha Winthor" required className="w-full px-4 py-3 border border-slate-200 rounded-lg text-base focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-colors" />

Use suas credenciais do Winthor (matrícula e senha).

); } export default function TelaLoginPage() { return (

Carregando…

}>
); }