added redirect based in type user

This commit is contained in:
2025-11-21 08:43:38 -06:00
parent 9c4b474225
commit 19db5ec5cb
4 changed files with 25 additions and 5 deletions
+10
View File
@@ -13,6 +13,7 @@
"@zxing/library": "^0.21.3",
"axios": "^1.13.2",
"js-cookie": "^3.0.5",
"jwt-decode": "^4.0.0",
"next": "16.0.2",
"react": "19.2.0",
"react-dom": "19.2.0",
@@ -4978,6 +4979,15 @@
"node": ">=4.0"
}
},
"node_modules/jwt-decode": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz",
"integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==",
"license": "MIT",
"engines": {
"node": ">=18"
}
},
"node_modules/keyv": {
"version": "4.5.4",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
+1
View File
@@ -14,6 +14,7 @@
"@zxing/library": "^0.21.3",
"axios": "^1.13.2",
"js-cookie": "^3.0.5",
"jwt-decode": "^4.0.0",
"next": "16.0.2",
"react": "19.2.0",
"react-dom": "19.2.0",
+13 -4
View File
@@ -7,6 +7,7 @@ import Image from "next/image";
import axios from "axios";
import { useRouter } from "next/navigation";
import toast from "react-hot-toast";
import { jwtDecode } from "jwt-decode";
export default function Login() {
const [nombre, setNombre] = useState("");
@@ -31,7 +32,18 @@ export default function Login() {
const { token } = response.data;
document.cookie = `token=${token}; path=/; SameSite=Strict`;
router.push("/escaner");
const decoded: any = jwtDecode(token);
const tipo = decoded?.tipoUsuario;
if (tipo === 2) {
router.push("/escaner");
} else if (tipo === 1) {
router.push("/equipoComputo");
} else {
toast.error("Tipo de usuario no válido");
}
} catch (err) {
if (axios.isAxiosError(err)) {
if (err.response) {
@@ -79,9 +91,6 @@ export default function Login() {
<button type="submit" disabled={loading}>
{loading ? "Buscando..." : "Iniciar sesión"}
</button>
{/* <Link href={"/forgotPassword"}>Olvidaste Contraseña?</Link> */}
{/* <Link href={"/crearCuenta"}>Crear Cuenta</Link> */}
</form>
</div>
+1 -1
View File
@@ -47,7 +47,7 @@ table {
}
thead th {
background-color: #0056b3;
background-color: #003e79;
color: #fff;
text-align: left;
padding: 14px;