added redirect based in type user
This commit is contained in:
Generated
+10
@@ -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",
|
||||
|
||||
@@ -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
@@ -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>
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ table {
|
||||
}
|
||||
|
||||
thead th {
|
||||
background-color: #0056b3;
|
||||
background-color: #003e79;
|
||||
color: #fff;
|
||||
text-align: left;
|
||||
padding: 14px;
|
||||
|
||||
Reference in New Issue
Block a user