react-ecosistema-unp 1.7.1-8.pre-8 → 1.7.1-8.pre-9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useLocation as
|
|
4
|
-
import { j as
|
|
5
|
-
const
|
|
6
|
-
const [
|
|
7
|
-
if ((await fetch(`${
|
|
1
|
+
import { jsx as v } from "react/jsx-runtime";
|
|
2
|
+
import { useState as _, useEffect as S } from "react";
|
|
3
|
+
import { useLocation as U, Outlet as g } from "react-router-dom";
|
|
4
|
+
import { j as u } from "../../index-CuHybtft.js";
|
|
5
|
+
const y = () => {
|
|
6
|
+
const [p, t] = _(!1), m = U(), s = `${window.location.protocol}//${window.location.host}/`, a = `${window.location.host}`, w = async () => {
|
|
7
|
+
if ((await fetch(`${s}api-auth/auth/refresh_token/`, {
|
|
8
8
|
method: "POST",
|
|
9
9
|
headers: {
|
|
10
10
|
"Content-Type": "application/json"
|
|
@@ -13,68 +13,52 @@ const R = () => {
|
|
|
13
13
|
})).ok)
|
|
14
14
|
return !0;
|
|
15
15
|
throw new Error("Error al refrescar token de Microsoft");
|
|
16
|
-
}, p = async (d) => {
|
|
17
|
-
const h = await fetch(`${t}api-auth/users/role_by_user/`, {
|
|
18
|
-
method: "POST",
|
|
19
|
-
headers: {
|
|
20
|
-
"Content-Type": "application/json"
|
|
21
|
-
},
|
|
22
|
-
credentials: "include",
|
|
23
|
-
body: JSON.stringify({ id_usuario: d })
|
|
24
|
-
});
|
|
25
|
-
if (h.ok)
|
|
26
|
-
return (await h.json()).roles.map((n) => n.id_rol);
|
|
27
|
-
throw new Error("Error al obtener los roles del usuario");
|
|
28
16
|
};
|
|
29
|
-
return
|
|
17
|
+
return S(() => {
|
|
30
18
|
const d = async () => {
|
|
31
19
|
try {
|
|
32
|
-
if ((await fetch(`${
|
|
20
|
+
if ((await fetch(`${s}api-auth/auth/validate_jwt/`, {
|
|
33
21
|
method: "POST",
|
|
34
22
|
headers: {
|
|
35
23
|
"Content-Type": "application/json"
|
|
36
24
|
},
|
|
37
25
|
credentials: "include"
|
|
38
26
|
})).ok) {
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
const
|
|
27
|
+
const i = sessionStorage.getItem("user_token");
|
|
28
|
+
if (i) {
|
|
29
|
+
const f = u(i).datos_basicos.servicios.map((e) => e.url).filter((e) => !!e), r = m.pathname, n = f.map(
|
|
42
30
|
(e) => e.startsWith("/") ? e : `/${e}`
|
|
43
|
-
),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
);
|
|
48
|
-
console.log(u, l), m && l ? s(!0) : (s(!1), sessionStorage.removeItem("user_token"), window.location.href = t);
|
|
31
|
+
), l = r.startsWith("/") ? r : `/${r}`;
|
|
32
|
+
n.some(
|
|
33
|
+
(e) => l.startsWith(e)
|
|
34
|
+
) ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
|
|
49
35
|
} else
|
|
50
|
-
|
|
36
|
+
t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
|
|
51
37
|
} else
|
|
52
38
|
throw new Error("Token inválido");
|
|
53
39
|
} catch {
|
|
54
40
|
try {
|
|
55
|
-
if (await
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
const
|
|
41
|
+
if (await w()) {
|
|
42
|
+
const c = sessionStorage.getItem("user_token");
|
|
43
|
+
if (c) {
|
|
44
|
+
const r = u(c).datos_basicos.servicios.map((o) => o.url).filter((o) => !!o), n = m.pathname, l = r.map(
|
|
59
45
|
(o) => o.startsWith("/") ? o : `/${o}`
|
|
60
|
-
),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
);
|
|
65
|
-
console.log(l, e), u && e ? s(!0) : (s(!1), sessionStorage.removeItem("user_token"), window.location.href = t);
|
|
46
|
+
), h = n.startsWith("/") ? n : `/${n}`;
|
|
47
|
+
l.some(
|
|
48
|
+
(o) => h.startsWith(o)
|
|
49
|
+
) ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
|
|
66
50
|
} else
|
|
67
|
-
|
|
51
|
+
t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
|
|
68
52
|
} else
|
|
69
53
|
throw new Error("No se pudo refrescar el token.");
|
|
70
54
|
} catch {
|
|
71
|
-
sessionStorage.removeItem("user_token"), window.location.href =
|
|
55
|
+
sessionStorage.removeItem("user_token"), window.location.href = s, t(!1);
|
|
72
56
|
}
|
|
73
57
|
}
|
|
74
58
|
};
|
|
75
|
-
|
|
76
|
-
}, []),
|
|
59
|
+
a.includes("ecosistemadesarrollo") || a.includes("ecosistemapruebas") || a.includes("ecosistemaprov") || a.includes("ecosistema") ? d() : (console.warn("ProtectedRoute is disabled in the local development environment."), t(!0));
|
|
60
|
+
}, []), p ? /* @__PURE__ */ v(g, {}) : null;
|
|
77
61
|
};
|
|
78
62
|
export {
|
|
79
|
-
|
|
63
|
+
y as ProtectedRoute
|
|
80
64
|
};
|