fix login

This commit is contained in:
2025-10-28 15:54:11 -06:00
parent 8443eabefb
commit d760a92a9c
3 changed files with 61 additions and 50 deletions
-28
View File
@@ -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",
+6 -7
View File
@@ -13,8 +13,12 @@ export default function Dashboard() {
const [search, setSearch] = useState("");
const [lastScan, setLastScan] = useState<string | null>(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
}
};
+55 -15
View File
@@ -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<HTMLFormElement>) => {
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() {
<div>
<label>Usuario</label>
<input
type="email"
placeholder="Correo"
value={email}
onChange={(e) => setEmail(e.target.value)}
type="text"
placeholder="Coloca tu nombre de usuario"
value={nombre}
onChange={(e) => setNombre(e.target.value)}
required
/>
</div>
@@ -48,7 +58,7 @@ export default function Login() {
<label>Contraseña</label>
<input
type="password"
placeholder="Contraseña"
placeholder="Coloca tu contraseña"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
@@ -62,24 +72,54 @@ export default function Login() {
<div className="image-collage">
<div className="collage-item collage-1">
<Image src="/Piedra.jpg" alt="UNAM Icatlán" fill style={{ objectFit: 'cover' }} />
<Image
src="/Piedra.jpg"
alt="UNAM Icatlán"
fill
style={{ objectFit: "cover" }}
/>
</div>
<div className="collage-item collage-2">
<Image src="/image 1.png" alt="UNAM Icatlán" fill style={{ objectFit: 'cover' }} />
<Image
src="/image 1.png"
alt="UNAM Icatlán"
fill
style={{ objectFit: "cover" }}
/>
</div>
<div className="collage-item collage-3">
<Image src="/estrella.jpg" alt="UNAM Icatlán" fill style={{ objectFit: 'cover' }} />
<Image
src="/estrella.jpg"
alt="UNAM Icatlán"
fill
style={{ objectFit: "cover" }}
/>
</div>
<div className="collage-item collage-4">
<Image src="/sorjuana.jpg" alt="UNAM Icatlán" fill style={{ objectFit: 'cover' }} />
<Image
src="/sorjuana.jpg"
alt="UNAM Icatlán"
fill
style={{ objectFit: "cover" }}
/>
</div>
<div className="collage-item collage-5">
<Image src="/fes.jpg" alt="UNAM Icatlán" fill style={{ objectFit: 'cover' }} />
<Image
src="/fes.jpg"
alt="UNAM Icatlán"
fill
style={{ objectFit: "cover" }}
/>
</div>
<div className="collage-item collage-6">
<Image src="/picachu.jpg" alt="UNAM Icatlán" fill style={{ objectFit: 'cover' }} />
<Image
src="/picachu.jpg"
alt="UNAM Icatlán"
fill
style={{ objectFit: "cover" }}
/>
</div>
</div>
</section>
);
}
}