react-ecosistema-unp 1.8.0-pre.6 → 1.8.0-pre.7
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,59 +1,66 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useLocation as
|
|
4
|
-
import { j as
|
|
5
|
-
const
|
|
6
|
-
const [k,
|
|
7
|
-
|
|
1
|
+
import { jsx as g } from "react/jsx-runtime";
|
|
2
|
+
import { useState as v, useEffect as I } from "react";
|
|
3
|
+
import { useLocation as _, Outlet as S } from "react-router-dom";
|
|
4
|
+
import { j as w } from "../../index-CuHybtft.js";
|
|
5
|
+
const E = () => {
|
|
6
|
+
const [k, s] = v(!1), h = _(), r = `${window.location.protocol}//${window.location.host}/`, c = `${window.location.host}`, p = async () => {
|
|
7
|
+
const l = await fetch(`${r}api-auth/auth/refresh_token/`, {
|
|
8
8
|
method: "POST",
|
|
9
9
|
headers: {
|
|
10
10
|
"Content-Type": "application/json",
|
|
11
11
|
Authorization: `Bearer ${localStorage.getItem("access_token")}`
|
|
12
12
|
},
|
|
13
13
|
credentials: "include"
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
});
|
|
15
|
+
if (l.ok) {
|
|
16
|
+
const o = (await l.json()).token;
|
|
17
|
+
return localStorage.setItem("access_token", o), !0;
|
|
18
|
+
} else
|
|
19
|
+
throw new Error("Error al refrescar token de Microsoft");
|
|
17
20
|
};
|
|
18
|
-
return
|
|
19
|
-
const
|
|
21
|
+
return I(() => {
|
|
22
|
+
const l = async () => {
|
|
20
23
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const i = localStorage.getItem("access_token");
|
|
25
|
+
if (console.warn("Inicio del PRotectedRoute"), console.warn("Access token recuperado: ", i), i) {
|
|
26
|
+
const o = localStorage.getItem("auth_state");
|
|
27
|
+
if (console.warn("Auth state recuperado: ", o), o) {
|
|
28
|
+
console.warn("Inicio de la validación de roles: ", o);
|
|
29
|
+
const u = w(o).user.servicios.map((e) => e.url).filter((e) => !!e), a = h.pathname, n = u.map(
|
|
25
30
|
(e) => e.startsWith("/") ? e : `/${e}`
|
|
26
|
-
),
|
|
27
|
-
|
|
28
|
-
(e) =>
|
|
29
|
-
) ?
|
|
31
|
+
), d = a.startsWith("/") ? a : `/${a}`;
|
|
32
|
+
n.some(
|
|
33
|
+
(e) => d.startsWith(e)
|
|
34
|
+
) ? s(!0) : (console.warn("No hay match con los roles del usuario"), s(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = r);
|
|
30
35
|
} else
|
|
31
|
-
|
|
36
|
+
console.warn("No se pudo recuperar el auth_state"), s(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = r;
|
|
32
37
|
} else
|
|
33
|
-
throw new Error("Token inválido");
|
|
38
|
+
throw console.warn("No se pudo recuperar el access_token"), new Error("Token inválido");
|
|
34
39
|
} catch {
|
|
40
|
+
console.warn("Inicio del try-catch");
|
|
35
41
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
const o = await p();
|
|
43
|
+
if (console.warn("Token refrescado"), o) {
|
|
44
|
+
const m = localStorage.getItem("auth_state");
|
|
45
|
+
if (m) {
|
|
46
|
+
const a = w(m).user.servicios.map((t) => t.url).filter((t) => !!t), n = h.pathname, d = a.map(
|
|
40
47
|
(t) => t.startsWith("/") ? t : `/${t}`
|
|
41
|
-
),
|
|
42
|
-
|
|
43
|
-
(t) =>
|
|
44
|
-
) ?
|
|
48
|
+
), f = n.startsWith("/") ? n : `/${n}`;
|
|
49
|
+
d.some(
|
|
50
|
+
(t) => f.startsWith(t)
|
|
51
|
+
) ? s(!0) : (s(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = r);
|
|
45
52
|
} else
|
|
46
|
-
|
|
53
|
+
s(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = r;
|
|
47
54
|
} else
|
|
48
55
|
throw new Error("No se pudo refrescar el token.");
|
|
49
56
|
} catch {
|
|
50
|
-
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href =
|
|
57
|
+
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = r, s(!1);
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
};
|
|
54
|
-
|
|
55
|
-
}, []), k ? /* @__PURE__ */
|
|
61
|
+
c.includes("ecosistemadesarrollo") || c.includes("ecosistemapruebas") || c.includes("ecosistemaprov") || c.includes("ecosistema") ? l() : (console.warn("ProtectedRoute is disabled in the local development environment."), s(!0));
|
|
62
|
+
}, []), k ? /* @__PURE__ */ g(S, {}) : null;
|
|
56
63
|
};
|
|
57
64
|
export {
|
|
58
|
-
|
|
65
|
+
E as ProtectedRoute
|
|
59
66
|
};
|