From d760a92a9c837c178553d0c43b5223f38a61694a Mon Sep 17 00:00:00 2001 From: IO420 <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 28 Oct 2025 15:54:11 -0600 Subject: [PATCH] fix login --- package-lock.json | 28 ------------ src/app/(Operador)/Escaner/page.tsx | 13 +++--- src/components/Login.tsx | 70 ++++++++++++++++++++++------- 3 files changed, 61 insertions(+), 50 deletions(-) diff --git a/package-lock.json b/package-lock.json index 63ce66d..dd3f18e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "@ericblade/quagga2": "^1.8.4", "@zxing/library": "^0.21.3", "axios": "^1.13.1", - "axios": "^1.13.1", "next": "15.5.6", "react": "19.1.0", "react-dom": "19.1.0" @@ -2222,33 +2221,6 @@ "node": ">=4" } }, - "node_modules/axios": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.1.tgz", - "integrity": "sha512-hU4EGxxt+j7TQijx1oYdAjw4xuIp1wRQSsbMFwSthCWeBQur1eF+qJ5iQ5sN3Tw8YRzQNKb8jszgBdMDVqwJcw==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.4", - "proxy-from-env": "^1.1.0" - } - }, - "node_modules/axios/node_modules/form-data": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz", - "integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "es-set-tostringtag": "^2.1.0", - "hasown": "^2.0.2", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/axios": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.1.tgz", diff --git a/src/app/(Operador)/Escaner/page.tsx b/src/app/(Operador)/Escaner/page.tsx index 8d1d2ff..fdf5936 100644 --- a/src/app/(Operador)/Escaner/page.tsx +++ b/src/app/(Operador)/Escaner/page.tsx @@ -13,8 +13,12 @@ export default function Dashboard() { const [search, setSearch] = useState(""); const [lastScan, setLastScan] = useState(null); + interface equipo { + id: number; + } + const buscarEquipo = async () => { - const encontrado = await axios.get(""); + const encontrado: equipo = await axios.get(""); if (encontrado) { // Redirige a la vista de edición con el ID del equipo @@ -28,17 +32,12 @@ export default function Dashboard() { setLastScan(code); setIsScanning(false); - const encontrado = await axios.get(""); + const encontrado: equipo = await axios.get(""); if (encontrado) { router.push(`/Editar?equipoId=${encontrado.id}`); } else { -<<<<<<< HEAD router.push(`/AgregarEquipo?equipoId=${code}`); -======= - // 🚫 Si no existe, se puede registrar - router.push(`/AgregarEquipo`); ->>>>>>> 8457542e8b63924894ebfa2f3148c3bc24a14a59 } }; diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 3bafd68..51ee633 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -6,25 +6,35 @@ import "../app/styles/base/globales.scss"; import Image from "next/image"; import Link from "next/link"; import axios from "axios"; +import { useRouter } from "next/router"; export default function Login() { - const [email, setEmail] = useState(""); + const [nombre, setNombre] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); + const router = useRouter(); + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); setLoading(true); - try{ - const response = await axios.post('/api/login', { email, password }); + try { + const response = await axios.post(`${process.env.API_URL}/auth/login`, { + nombre, + contraseña: password, + }); + const token = response.data; + + document.cookie = `token=${token}; path=/; SameSite=Strict`; } catch (err) { console.error("Error en la solicitud:", err); setError("Error al conectar con el servidor"); } finally { setLoading(false); + router.push("/Escaner"); } }; @@ -37,10 +47,10 @@ export default function Login() {
setEmail(e.target.value)} + type="text" + placeholder="Coloca tu nombre de usuario" + value={nombre} + onChange={(e) => setNombre(e.target.value)} required />
@@ -48,7 +58,7 @@ export default function Login() { setPassword(e.target.value)} required @@ -62,24 +72,54 @@ export default function Login() {
- UNAM Icatlán + UNAM Icatlán
- UNAM Icatlán + UNAM Icatlán
- UNAM Icatlán + UNAM Icatlán
- UNAM Icatlán + UNAM Icatlán
- UNAM Icatlán + UNAM Icatlán
- UNAM Icatlán + UNAM Icatlán
); -} \ No newline at end of file +}