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