add middleware
This commit is contained in:
@@ -11,7 +11,6 @@ export default function Page() {
|
||||
<section className="containerSection">
|
||||
<h2 className="title">EQUIPOS ACTIVOS Y EN MANTENIMIENTO</h2>
|
||||
|
||||
<div className="mainContainer">
|
||||
<Toggle
|
||||
defaultView="Equipos"
|
||||
options={[
|
||||
@@ -121,7 +120,6 @@ export default function Page() {
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
/* Add these new styles to your CSS file */
|
||||
.mainContainer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 20px; /* Adjust the spacing as needed */
|
||||
flex-wrap: wrap; /* Allows components to wrap on smaller screens */
|
||||
}
|
||||
|
||||
.availableTablesContainer {
|
||||
/* You can add specific styles for the table list here */
|
||||
|
||||
@@ -12,8 +12,6 @@ export default function Page() {
|
||||
<section className="containerSection">
|
||||
<h2 className="title"> ASIGNACION DE EQUIPOS </h2>
|
||||
|
||||
<div className="mainContainer">
|
||||
{/* Toggle component for 'Asignar' and 'Liberar' tabs */}
|
||||
<Toggle
|
||||
defaultView="Asignar"
|
||||
options={[
|
||||
@@ -47,8 +45,6 @@ export default function Page() {
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
/* Add these new styles to your CSS file */
|
||||
.mainContainer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 20px; /* Adjust the spacing as needed */
|
||||
flex-wrap: wrap; /* Allows components to wrap on smaller screens */
|
||||
}
|
||||
|
||||
.availableTablesContainer {
|
||||
/* You can add specific styles for the table list here */
|
||||
|
||||
@@ -12,8 +12,6 @@ export default function Page() {
|
||||
<section className="containerSection">
|
||||
<h2 className="title"> ASIGNACION DE MESAS </h2>
|
||||
|
||||
<div className="mainContainer">
|
||||
{/* Toggle component for 'Asignar' and 'Liberar' tabs */}
|
||||
<Toggle
|
||||
defaultView="Asignar"
|
||||
options={[
|
||||
@@ -66,9 +64,6 @@ export default function Page() {
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
{/* This is the new component to display available tables */}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,80 +1,82 @@
|
||||
'use client';
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import { loginUser } from "@/app/lib/login";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import "./Login.css";
|
||||
|
||||
function Login() {
|
||||
const [user, setUser] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
const [user, setUser] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
|
||||
const handleLogin = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
const router = useRouter();
|
||||
|
||||
const data = await loginUser(user, password);
|
||||
const handleLogin = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
if ("error" in data) {
|
||||
setMessage(data.error);
|
||||
} else {
|
||||
localStorage.setItem("token", data.access_token);
|
||||
setMessage("Inicio de sesión exitoso");
|
||||
console.log("Respuesta del servidor:", data);
|
||||
}
|
||||
};
|
||||
const data = await loginUser(user, password);
|
||||
|
||||
return (
|
||||
<section className='centerGrid containerSection'>
|
||||
if ("error" in data) {
|
||||
setMessage(data.error);
|
||||
} else {
|
||||
document.cookie = `token=${data.access_token}; path=/; SameSite=Strict`;
|
||||
setMessage("Inicio de sesión exitoso");
|
||||
router.push("/Impresiones");
|
||||
}
|
||||
};
|
||||
|
||||
<form
|
||||
className='login'
|
||||
onSubmit={handleLogin}
|
||||
>
|
||||
<h2 className='title'>Inicio de sesión</h2>
|
||||
return (
|
||||
<section className="centerGrid containerSection">
|
||||
<form className="login" onSubmit={handleLogin}>
|
||||
<h2 className="title">Inicio de sesión</h2>
|
||||
|
||||
<div className='containerInput'>
|
||||
<label className='label'>Usuario</label>
|
||||
<input
|
||||
type='text'
|
||||
value={user}
|
||||
onChange={(e) => setUser(e.target.value)}
|
||||
placeholder='Coloca tu usuario...'
|
||||
/>
|
||||
</div>
|
||||
<div className="containerInput">
|
||||
<label className="label">Usuario</label>
|
||||
<input
|
||||
type="text"
|
||||
value={user}
|
||||
onChange={(e) => setUser(e.target.value)}
|
||||
placeholder="Coloca tu usuario..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='containerInput relative'>
|
||||
<label className='label'>Contraseña</label>
|
||||
<input
|
||||
type='password'
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder='Coloca tu contraseña...'
|
||||
/>
|
||||
<span
|
||||
//onClick={() => setShowPassword(!showPassword)}
|
||||
//className={showPassword ? 'eyeOpen' : 'eyeClose'}
|
||||
/>
|
||||
</div>
|
||||
<div className="containerInput relative">
|
||||
<label className="label">Contraseña</label>
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Coloca tu contraseña..."
|
||||
/>
|
||||
<span
|
||||
//onClick={() => setShowPassword(!showPassword)}
|
||||
//className={showPassword ? 'eyeOpen' : 'eyeClose'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
className='button buttonSearch'
|
||||
style={{ maxWidth: '100%', width: '100%' }}
|
||||
type='submit'
|
||||
>Iniciar sesión
|
||||
</button>
|
||||
<button
|
||||
className="button buttonSearch"
|
||||
style={{ maxWidth: "100%", width: "100%" }}
|
||||
type="submit"
|
||||
>
|
||||
Iniciar sesión
|
||||
</button>
|
||||
|
||||
{message &&
|
||||
<div
|
||||
className={`messageBox ${message.includes('exitoso') ? 'success' : 'error'}`}
|
||||
style={{ marginTop: '10px' }}
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
{message && (
|
||||
<div
|
||||
className={`messageBox ${
|
||||
message.includes("exitoso") ? "success" : "error"
|
||||
}`}
|
||||
style={{ marginTop: "10px" }}
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default Login;
|
||||
//IO
|
||||
//IO
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ export const metadata: Metadata = {
|
||||
title: "Servicio AT",
|
||||
description: "Servicio de administracion de la FES Acatlan",
|
||||
authors: [{ name: "FES Acatlán" }],
|
||||
creator: "Lino,Axel,Carlos",
|
||||
creator: "Lino,Carlos,Axel",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
const token = request.cookies.get('token');
|
||||
|
||||
if (!token) {
|
||||
console.log('No hay token, redirigiendo a la página de inicio de sesión');
|
||||
return NextResponse.redirect(new URL('/', request.url));
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
//IO
|
||||
@@ -0,0 +1,34 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
const token = request.cookies.get("token");
|
||||
|
||||
if (!token) {
|
||||
console.log("No hay token, redirigiendo a la página de inicio de sesión");
|
||||
return NextResponse.redirect(new URL("/", request.url));
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
"/Reportes",
|
||||
"/Monitor",
|
||||
"/QuitarSancion",
|
||||
"/Programas",
|
||||
"/Mensajes",
|
||||
"/Inscritos",
|
||||
"/Inscripciones",
|
||||
"/InformacionEquipo",
|
||||
"/Impresiones",
|
||||
"/CambiarPass",
|
||||
"/BitacoraSanciones",
|
||||
"/AsignacionMesas",
|
||||
"/AsignacionEquipo",
|
||||
"/Alta",
|
||||
"/AgregarTiempo",
|
||||
"/ActivosMantenimiento"],
|
||||
};
|
||||
//IO
|
||||
Reference in New Issue
Block a user