react-ecosistema-unp 1.7.18 → 1.7.19
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
1
|
import { jsx as v } from "react/jsx-runtime";
|
|
2
|
-
import { useState as
|
|
3
|
-
import {
|
|
4
|
-
import { j as
|
|
5
|
-
const
|
|
6
|
-
const [
|
|
7
|
-
if ((await fetch(`${
|
|
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"
|
|
@@ -14,50 +14,51 @@ const E = () => {
|
|
|
14
14
|
return !0;
|
|
15
15
|
throw new Error("Error al refrescar token de Microsoft");
|
|
16
16
|
};
|
|
17
|
-
return
|
|
18
|
-
|
|
17
|
+
return S(() => {
|
|
18
|
+
const d = async () => {
|
|
19
19
|
try {
|
|
20
|
-
if ((await fetch(`${
|
|
20
|
+
if ((await fetch(`${s}api-auth/auth/validate_jwt/`, {
|
|
21
21
|
method: "POST",
|
|
22
22
|
headers: {
|
|
23
23
|
"Content-Type": "application/json"
|
|
24
24
|
},
|
|
25
25
|
credentials: "include"
|
|
26
26
|
})).ok) {
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const f =
|
|
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(
|
|
30
30
|
(e) => e.startsWith("/") ? e : `/${e}`
|
|
31
|
-
),
|
|
31
|
+
), l = r.startsWith("/") ? r : `/${r}`;
|
|
32
32
|
n.some(
|
|
33
|
-
(e) =>
|
|
34
|
-
) ?
|
|
33
|
+
(e) => l.startsWith(e)
|
|
34
|
+
) ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
|
|
35
35
|
} else
|
|
36
|
-
|
|
36
|
+
t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
|
|
37
37
|
} else
|
|
38
38
|
throw new Error("Token inválido");
|
|
39
39
|
} catch {
|
|
40
40
|
try {
|
|
41
|
-
if (await
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
const r =
|
|
45
|
-
(
|
|
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(
|
|
45
|
+
(o) => o.startsWith("/") ? o : `/${o}`
|
|
46
46
|
), h = n.startsWith("/") ? n : `/${n}`;
|
|
47
|
-
|
|
48
|
-
(
|
|
49
|
-
) ?
|
|
47
|
+
l.some(
|
|
48
|
+
(o) => h.startsWith(o)
|
|
49
|
+
) ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
|
|
50
50
|
} else
|
|
51
|
-
|
|
51
|
+
t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
|
|
52
52
|
} else
|
|
53
53
|
throw new Error("No se pudo refrescar el token.");
|
|
54
54
|
} catch {
|
|
55
|
-
sessionStorage.removeItem("user_token"), window.location.href =
|
|
55
|
+
sessionStorage.removeItem("user_token"), window.location.href = s, t(!1);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
}
|
|
59
|
-
|
|
58
|
+
};
|
|
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;
|
|
60
61
|
};
|
|
61
62
|
export {
|
|
62
|
-
|
|
63
|
+
y as ProtectedRoute
|
|
63
64
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { jsx as c } from "react/jsx-runtime";
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useNavigate as
|
|
2
|
+
import { useState as d, useEffect as h } from "react";
|
|
3
|
+
import { useNavigate as u, Outlet as f } from "react-router-dom";
|
|
4
4
|
const k = () => {
|
|
5
|
-
const [
|
|
6
|
-
|
|
5
|
+
const [r, e] = d(!1), s = u(), o = `${window.location.protocol}//${window.location.host}/`, t = `${window.location.host}`;
|
|
6
|
+
if (t.includes("localhost"))
|
|
7
|
+
return console.warn("ProtectedRoute is disabled in the local development environment."), null;
|
|
8
|
+
const a = async () => {
|
|
9
|
+
if ((await fetch(`${o}api-auth/auth/refresh_token/`, {
|
|
7
10
|
method: "POST",
|
|
8
11
|
headers: {
|
|
9
12
|
"Content-Type": "application/json"
|
|
@@ -13,22 +16,22 @@ const k = () => {
|
|
|
13
16
|
return !0;
|
|
14
17
|
throw new Error("Error al refrescar token de Microsoft");
|
|
15
18
|
};
|
|
16
|
-
return
|
|
17
|
-
|
|
19
|
+
return h(() => {
|
|
20
|
+
const n = async () => {
|
|
18
21
|
try {
|
|
19
|
-
if ((await fetch(`${
|
|
22
|
+
if ((await fetch(`${o}api-auth/auth/validate_jwt/`, {
|
|
20
23
|
method: "POST",
|
|
21
24
|
headers: {
|
|
22
25
|
"Content-Type": "application/json"
|
|
23
26
|
},
|
|
24
27
|
credentials: "include"
|
|
25
28
|
})).ok)
|
|
26
|
-
|
|
29
|
+
e(!0);
|
|
27
30
|
else
|
|
28
31
|
try {
|
|
29
|
-
if (await
|
|
32
|
+
if (await a())
|
|
30
33
|
(await fetch(
|
|
31
|
-
`${
|
|
34
|
+
`${o}api-auth/auth/validate_jwt/`,
|
|
32
35
|
{
|
|
33
36
|
method: "POST",
|
|
34
37
|
headers: {
|
|
@@ -36,17 +39,18 @@ const k = () => {
|
|
|
36
39
|
},
|
|
37
40
|
credentials: "include"
|
|
38
41
|
}
|
|
39
|
-
)).ok ?
|
|
42
|
+
)).ok ? e(!0) : (sessionStorage.removeItem("user_token"), window.location.href = o, e(!1));
|
|
40
43
|
else
|
|
41
44
|
throw new Error("No se pudo refrescar el token.");
|
|
42
45
|
} catch {
|
|
43
|
-
sessionStorage.removeItem("user_token"), window.location.href = e;
|
|
46
|
+
sessionStorage.removeItem("user_token"), window.location.href = o, e(!1);
|
|
44
47
|
}
|
|
45
48
|
} catch {
|
|
46
|
-
sessionStorage.removeItem("user_token"), window.location.href = e;
|
|
49
|
+
sessionStorage.removeItem("user_token"), window.location.href = o, e(!1);
|
|
47
50
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
51
|
+
};
|
|
52
|
+
t.includes("localhost") ? (console.warn("ProtectedRoute is disabled in the local development environment."), e(!0)) : n();
|
|
53
|
+
}, [s]), r ? /* @__PURE__ */ c(f, {}) : null;
|
|
50
54
|
};
|
|
51
55
|
export {
|
|
52
56
|
k as UserRoute
|