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