react-ecosistema-unp 1.8.0-pre.1 → 1.8.0-pre.2
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.
- package/dist/auth/hooks/useFinalizarSesion.js +14 -14
- package/dist/shared/app-list/AppList.js +12 -12
- package/dist/shared/menu-lateral/MenuLateral.js +16 -16
- package/dist/utils/components/ProtectedRoute.js +25 -25
- package/dist/utils/components/UserRoute.js +14 -14
- package/package.json +1 -1
- package/dist/lib/utils/components/fetchInterceptor.d.ts +0 -7
- package/dist/lib/utils/fetch-interceptor/fetchInterceptor.d.ts +0 -7
- package/dist/utils/components/fetchInterceptor.js +0 -56
- package/dist/utils/fetch-interceptor/fetchInterceptor.js +0 -56
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { FinSesionService as
|
|
1
|
+
import { FinSesionService as i } from "../services/FinSesionService.js";
|
|
2
2
|
import { y as a } from "../../index-BUe3EJDH.js";
|
|
3
3
|
import { useState as c, useEffect as l } from "react";
|
|
4
4
|
import { j as m } from "../../index-CuHybtft.js";
|
|
5
|
-
const
|
|
6
|
-
const [
|
|
5
|
+
const d = () => {
|
|
6
|
+
const [o, n] = c(null), r = `${window.location.protocol}//${window.location.host}/`;
|
|
7
7
|
return l(() => {
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
const
|
|
11
|
-
|
|
8
|
+
const e = localStorage.getItem("auth_state");
|
|
9
|
+
if (e) {
|
|
10
|
+
const t = m(e);
|
|
11
|
+
n(t);
|
|
12
12
|
}
|
|
13
13
|
}, []), { FinSesion: () => {
|
|
14
14
|
a.promise(
|
|
15
|
-
new Promise(async (
|
|
15
|
+
new Promise(async (e, t) => {
|
|
16
16
|
try {
|
|
17
|
-
await
|
|
18
|
-
} catch (
|
|
19
|
-
|
|
17
|
+
await i((o == null ? void 0 : o.user.username) || "", r), e(!0);
|
|
18
|
+
} catch (s) {
|
|
19
|
+
t(s);
|
|
20
20
|
} finally {
|
|
21
|
-
sessionStorage.removeItem("user_token"), setTimeout(() => {
|
|
22
|
-
window.location.href =
|
|
21
|
+
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), setTimeout(() => {
|
|
22
|
+
window.location.href = r;
|
|
23
23
|
}, 1e3);
|
|
24
24
|
}
|
|
25
25
|
}),
|
|
@@ -32,5 +32,5 @@ const p = () => {
|
|
|
32
32
|
} };
|
|
33
33
|
};
|
|
34
34
|
export {
|
|
35
|
-
|
|
35
|
+
d as useFinalizarSesion
|
|
36
36
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as o, jsxs as r } from "react/jsx-runtime";
|
|
2
2
|
import { useState as d, useEffect as h } from "react";
|
|
3
|
-
import { F as
|
|
3
|
+
import { F as n, f as u, g as f, h as v, i as z } from "../../index-D3WseyJh.js";
|
|
4
4
|
import { z as N } from "../../index-DDjnZyBf.js";
|
|
5
5
|
import { G as g } from "../../iconBase-LROS5hdG.js";
|
|
6
6
|
import { j as w } from "../../index-CuHybtft.js";
|
|
7
|
-
import { N as
|
|
8
|
-
import '../../assets/AppList.css';function
|
|
7
|
+
import { N as U } from "../../NavDropdown-ei8eIwIE.js";
|
|
8
|
+
import '../../assets/AppList.css';function b(s) {
|
|
9
9
|
return g({ tag: "svg", attr: { fill: "currentColor", viewBox: "0 0 16 16" }, child: [{ tag: "path", attr: { d: "M1 2a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1zM1 7a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1zM1 12a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1z" }, child: [] }] })(s);
|
|
10
10
|
}
|
|
11
11
|
const F = {
|
|
12
|
-
Usuario: /* @__PURE__ */ o(
|
|
12
|
+
Usuario: /* @__PURE__ */ o(n, { size: 24, className: "icon-app-2" }),
|
|
13
13
|
"Asesor(a) poblacional": /* @__PURE__ */ o(u, { size: 24, className: "icon-app-2" }),
|
|
14
14
|
Radicador: /* @__PURE__ */ o(f, { size: 24, className: "icon-app-2" }),
|
|
15
15
|
"Reparto poblacional": /* @__PURE__ */ o(v, { size: 24, className: "icon-app-2" }),
|
|
@@ -23,23 +23,23 @@ const F = {
|
|
|
23
23
|
}, j = () => {
|
|
24
24
|
const [s, l] = d([]), e = location.pathname, c = e.startsWith("/") ? e : `/${e}`;
|
|
25
25
|
h(() => {
|
|
26
|
-
const a =
|
|
26
|
+
const a = localStorage.getItem("auth_state");
|
|
27
27
|
if (a)
|
|
28
28
|
try {
|
|
29
29
|
const i = w(a);
|
|
30
|
-
l(i.
|
|
30
|
+
l(i.user.servicios);
|
|
31
31
|
} catch (i) {
|
|
32
32
|
console.error("Error al decodificar el token:", i);
|
|
33
33
|
}
|
|
34
34
|
}, []);
|
|
35
|
-
const
|
|
35
|
+
const t = (a) => {
|
|
36
36
|
const i = `${window.location.protocol}//${window.location.host}/${a}`;
|
|
37
37
|
window.location.href = i;
|
|
38
38
|
};
|
|
39
39
|
return /* @__PURE__ */ o(
|
|
40
|
-
|
|
40
|
+
U,
|
|
41
41
|
{
|
|
42
|
-
title: /* @__PURE__ */ o(
|
|
42
|
+
title: /* @__PURE__ */ o(b, { className: "icono-app" }),
|
|
43
43
|
align: "end",
|
|
44
44
|
children: /* @__PURE__ */ o("div", { style: {
|
|
45
45
|
fontWeight: "400",
|
|
@@ -51,7 +51,7 @@ const F = {
|
|
|
51
51
|
"div",
|
|
52
52
|
{
|
|
53
53
|
className: `icon-wrapper ${c === "/" + i ? "active" : ""}`,
|
|
54
|
-
onClick: () =>
|
|
54
|
+
onClick: () => t(i),
|
|
55
55
|
children: [
|
|
56
56
|
p,
|
|
57
57
|
/* @__PURE__ */ o("span", { className: "icono-nombre-app", children: m })
|
|
@@ -64,9 +64,9 @@ const F = {
|
|
|
64
64
|
"div",
|
|
65
65
|
{
|
|
66
66
|
className: `icon-wrapper ${c === "/unp/ecosistema/usuario" ? "active" : ""}`,
|
|
67
|
-
onClick: () =>
|
|
67
|
+
onClick: () => t("unp/ecosistema/usuario"),
|
|
68
68
|
children: [
|
|
69
|
-
/* @__PURE__ */ o(
|
|
69
|
+
/* @__PURE__ */ o(n, { size: 24, className: "icon-app-2" }),
|
|
70
70
|
/* @__PURE__ */ o("span", { className: "icono-nombre-app", children: "Mi Perfil" })
|
|
71
71
|
]
|
|
72
72
|
},
|
|
@@ -68,10 +68,10 @@ function G(t) {
|
|
|
68
68
|
function W(t) {
|
|
69
69
|
return i({ tag: "svg", attr: { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, child: [{ tag: "path", attr: { d: "M17.8 19.2 16 11l3.5-3.5C21 6 21.5 4 21 3c-1-.5-3 0-4.5 1.5L13 8 4.8 6.2c-.5-.1-.9.1-1.1.5l-.3.5c-.2.5-.1 1 .3 1.3L9 12l-2 3H4l-1 1 3 2 2 3 1-1v-3l3-2 3.5 5.3c.3.4.8.5 1.3.3l.5-.2c.4-.3.6-.7.5-1.2z" }, child: [] }] })(t);
|
|
70
70
|
}
|
|
71
|
-
const z1 = ({ onToggle: t, isOpen:
|
|
72
|
-
const [N, f] = o(!0), [m, p] = o(null), k =
|
|
71
|
+
const z1 = ({ onToggle: t, isOpen: l, showConnectionStatus: x }) => {
|
|
72
|
+
const [N, f] = o(!0), [m, p] = o(null), k = l ? "sidebar-bar-panel open" : "sidebar-bar-panel", w = H(), { FinSesion: b } = C(), { connectionStatus: v } = A(), [z, c] = o(!1), [M, n] = o(""), h = `${window.location.host}`;
|
|
73
73
|
if (d(() => {
|
|
74
|
-
const r =
|
|
74
|
+
const r = localStorage.getItem("auth_state");
|
|
75
75
|
if (r) {
|
|
76
76
|
const s = u(r);
|
|
77
77
|
p(s);
|
|
@@ -79,21 +79,21 @@ const z1 = ({ onToggle: t, isOpen: c, showConnectionStatus: x }) => {
|
|
|
79
79
|
f(!1);
|
|
80
80
|
}, []), d(() => {
|
|
81
81
|
const r = setTimeout(() => {
|
|
82
|
-
const s =
|
|
82
|
+
const s = localStorage.getItem("auth_state");
|
|
83
83
|
if (s) {
|
|
84
|
-
const
|
|
85
|
-
p(
|
|
84
|
+
const _ = u(s);
|
|
85
|
+
p(_);
|
|
86
86
|
}
|
|
87
87
|
}, 2e3);
|
|
88
88
|
return () => clearTimeout(r);
|
|
89
89
|
}, []), d(() => {
|
|
90
|
-
h.includes("localhost") ? (
|
|
90
|
+
h.includes("localhost") ? (c(!0), n("Entorno local")) : h.includes("ecosistemadesarrollo") ? (c(!0), n("Entorno de desarrollo")) : h.includes("ecosistemapruebas") ? (c(!0), n("Entorno de pruebas")) : (c(!1), n(""));
|
|
91
91
|
}, []), N)
|
|
92
92
|
return /* @__PURE__ */ a(g, {});
|
|
93
|
-
const
|
|
94
|
-
|
|
93
|
+
const B = () => {
|
|
94
|
+
w("/unp/ecosistema/usuario");
|
|
95
95
|
};
|
|
96
|
-
return /* @__PURE__ */ a("div", { className: `container-fluid ${
|
|
96
|
+
return /* @__PURE__ */ a("div", { className: `container-fluid ${l ? "menu-open" : ""}`, children: /* @__PURE__ */ e("div", { className: k, children: [
|
|
97
97
|
/* @__PURE__ */ e("div", { className: "logo_details", children: [
|
|
98
98
|
/* @__PURE__ */ a(
|
|
99
99
|
"img",
|
|
@@ -104,7 +104,7 @@ const z1 = ({ onToggle: t, isOpen: c, showConnectionStatus: x }) => {
|
|
|
104
104
|
}
|
|
105
105
|
),
|
|
106
106
|
/* @__PURE__ */ a("div", { className: "logo-name", children: "EI - UNP" }),
|
|
107
|
-
|
|
107
|
+
l ? /* @__PURE__ */ a(
|
|
108
108
|
$,
|
|
109
109
|
{
|
|
110
110
|
className: "bx bx-menu i",
|
|
@@ -195,7 +195,7 @@ const z1 = ({ onToggle: t, isOpen: c, showConnectionStatus: x }) => {
|
|
|
195
195
|
] })
|
|
196
196
|
] }),
|
|
197
197
|
/* @__PURE__ */ e("div", { className: "profile-content", children: [
|
|
198
|
-
!
|
|
198
|
+
!l && x && /* @__PURE__ */ a(g, { children: v === "connected" ? /* @__PURE__ */ e("div", { className: "gear-tooltip-container", children: [
|
|
199
199
|
/* @__PURE__ */ e(
|
|
200
200
|
"svg",
|
|
201
201
|
{
|
|
@@ -257,7 +257,7 @@ const z1 = ({ onToggle: t, isOpen: c, showConnectionStatus: x }) => {
|
|
|
257
257
|
]
|
|
258
258
|
}
|
|
259
259
|
) }),
|
|
260
|
-
!
|
|
260
|
+
!l && z && /* @__PURE__ */ e("div", { className: "gear-tooltip-container", children: [
|
|
261
261
|
/* @__PURE__ */ a(
|
|
262
262
|
"svg",
|
|
263
263
|
{
|
|
@@ -291,15 +291,15 @@ const z1 = ({ onToggle: t, isOpen: c, showConnectionStatus: x }) => {
|
|
|
291
291
|
"div",
|
|
292
292
|
{
|
|
293
293
|
className: "profile-detail",
|
|
294
|
-
onClick:
|
|
294
|
+
onClick: B,
|
|
295
295
|
style: { cursor: "pointer" },
|
|
296
296
|
children: m && /* @__PURE__ */ e("div", { className: "name-job", style: { marginTop: "3px" }, children: [
|
|
297
|
-
/* @__PURE__ */ a("div", { className: "name text-truncate", style: { width: "200px" }, children: m.
|
|
297
|
+
/* @__PURE__ */ a("div", { className: "name text-truncate", style: { width: "200px" }, children: m.user.nombres }),
|
|
298
298
|
/* @__PURE__ */ a("div", { className: "job" })
|
|
299
299
|
] })
|
|
300
300
|
}
|
|
301
301
|
),
|
|
302
|
-
/* @__PURE__ */ a(F, { className: "icon", onClick:
|
|
302
|
+
/* @__PURE__ */ a(F, { className: "icon", onClick: b })
|
|
303
303
|
] })
|
|
304
304
|
] })
|
|
305
305
|
] }) });
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as v } from "react/jsx-runtime";
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useLocation as
|
|
2
|
+
import { useState as S, useEffect as g } from "react";
|
|
3
|
+
import { useLocation as _, Outlet as I } from "react-router-dom";
|
|
4
4
|
import { j as u } from "../../index-CuHybtft.js";
|
|
5
5
|
const y = () => {
|
|
6
|
-
const [p,
|
|
6
|
+
const [p, o] = S(!1), m = _(), 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: {
|
|
@@ -14,8 +14,8 @@ const y = () => {
|
|
|
14
14
|
return !0;
|
|
15
15
|
throw new Error("Error al refrescar token de Microsoft");
|
|
16
16
|
};
|
|
17
|
-
return
|
|
18
|
-
const
|
|
17
|
+
return g(() => {
|
|
18
|
+
const h = async () => {
|
|
19
19
|
try {
|
|
20
20
|
if ((await fetch(`${s}api-auth/auth/validate_jwt/`, {
|
|
21
21
|
method: "POST",
|
|
@@ -24,40 +24,40 @@ const y = () => {
|
|
|
24
24
|
},
|
|
25
25
|
credentials: "include"
|
|
26
26
|
})).ok) {
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
27
|
+
const c = localStorage.getItem("auth_state");
|
|
28
|
+
if (c) {
|
|
29
|
+
const d = u(c).user.servicios.map((e) => e.url).filter((e) => !!e), r = m.pathname, a = d.map(
|
|
30
30
|
(e) => e.startsWith("/") ? e : `/${e}`
|
|
31
|
-
),
|
|
32
|
-
|
|
33
|
-
(e) =>
|
|
34
|
-
) ?
|
|
31
|
+
), i = r.startsWith("/") ? r : `/${r}`;
|
|
32
|
+
a.some(
|
|
33
|
+
(e) => i.startsWith(e)
|
|
34
|
+
) ? o(!0) : (o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = s);
|
|
35
35
|
} else
|
|
36
|
-
|
|
36
|
+
o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = s;
|
|
37
37
|
} else
|
|
38
38
|
throw new Error("Token inválido");
|
|
39
39
|
} catch {
|
|
40
40
|
try {
|
|
41
41
|
if (await w()) {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
const r = u(
|
|
45
|
-
(
|
|
46
|
-
),
|
|
47
|
-
|
|
48
|
-
(
|
|
49
|
-
) ?
|
|
42
|
+
const l = localStorage.getItem("auth_state");
|
|
43
|
+
if (l) {
|
|
44
|
+
const r = u(l).user.servicios.map((t) => t.url).filter((t) => !!t), a = m.pathname, i = r.map(
|
|
45
|
+
(t) => t.startsWith("/") ? t : `/${t}`
|
|
46
|
+
), f = a.startsWith("/") ? a : `/${a}`;
|
|
47
|
+
i.some(
|
|
48
|
+
(t) => f.startsWith(t)
|
|
49
|
+
) ? o(!0) : (o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = s);
|
|
50
50
|
} else
|
|
51
|
-
|
|
51
|
+
o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_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 = s,
|
|
55
|
+
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = s, o(!1);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
|
|
60
|
-
}, []), p ? /* @__PURE__ */ v(
|
|
59
|
+
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
|
+
}, []), p ? /* @__PURE__ */ v(I, {}) : null;
|
|
61
61
|
};
|
|
62
62
|
export {
|
|
63
63
|
y as ProtectedRoute
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as c } from "react/jsx-runtime";
|
|
2
2
|
import { useState as d, useEffect as h } from "react";
|
|
3
|
-
import { useNavigate as u, Outlet as
|
|
3
|
+
import { useNavigate as u, Outlet as m } from "react-router-dom";
|
|
4
4
|
const k = () => {
|
|
5
|
-
const [
|
|
6
|
-
if (
|
|
5
|
+
const [a, e] = d(!1), s = u(), t = `${window.location.protocol}//${window.location.host}/`, o = `${window.location.host}`;
|
|
6
|
+
if (o.includes("localhost"))
|
|
7
7
|
return console.warn("ProtectedRoute is disabled in the local development environment."), null;
|
|
8
|
-
const
|
|
9
|
-
if ((await fetch(`${
|
|
8
|
+
const n = async () => {
|
|
9
|
+
if ((await fetch(`${t}api-auth/auth/refresh_token/`, {
|
|
10
10
|
method: "POST",
|
|
11
11
|
headers: {
|
|
12
12
|
"Content-Type": "application/json"
|
|
@@ -17,9 +17,9 @@ const k = () => {
|
|
|
17
17
|
throw new Error("Error al refrescar token de Microsoft");
|
|
18
18
|
};
|
|
19
19
|
return h(() => {
|
|
20
|
-
const
|
|
20
|
+
const r = async () => {
|
|
21
21
|
try {
|
|
22
|
-
if ((await fetch(`${
|
|
22
|
+
if ((await fetch(`${t}api-auth/auth/validate_jwt/`, {
|
|
23
23
|
method: "POST",
|
|
24
24
|
headers: {
|
|
25
25
|
"Content-Type": "application/json"
|
|
@@ -29,9 +29,9 @@ const k = () => {
|
|
|
29
29
|
e(!0);
|
|
30
30
|
else
|
|
31
31
|
try {
|
|
32
|
-
if (await
|
|
32
|
+
if (await n())
|
|
33
33
|
(await fetch(
|
|
34
|
-
`${
|
|
34
|
+
`${t}api-auth/auth/validate_jwt/`,
|
|
35
35
|
{
|
|
36
36
|
method: "POST",
|
|
37
37
|
headers: {
|
|
@@ -39,18 +39,18 @@ const k = () => {
|
|
|
39
39
|
},
|
|
40
40
|
credentials: "include"
|
|
41
41
|
}
|
|
42
|
-
)).ok ? e(!0) : (sessionStorage.removeItem("user_token"), window.location.href =
|
|
42
|
+
)).ok ? e(!0) : (sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = t, e(!1));
|
|
43
43
|
else
|
|
44
44
|
throw new Error("No se pudo refrescar el token.");
|
|
45
45
|
} catch {
|
|
46
|
-
sessionStorage.removeItem("user_token"), window.location.href =
|
|
46
|
+
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = t, e(!1);
|
|
47
47
|
}
|
|
48
48
|
} catch {
|
|
49
|
-
sessionStorage.removeItem("user_token"), window.location.href =
|
|
49
|
+
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = t, e(!1);
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
|
|
53
|
-
}, [s]),
|
|
52
|
+
o.includes("localhost") ? (console.warn("ProtectedRoute is disabled in the local development environment."), e(!0)) : r();
|
|
53
|
+
}, [s]), a ? /* @__PURE__ */ c(m, {}) : null;
|
|
54
54
|
};
|
|
55
55
|
export {
|
|
56
56
|
k as UserRoute
|
package/package.json
CHANGED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
window.originalFetch = window.fetch.bind(window);
|
|
2
|
-
let l = !1, h = null;
|
|
3
|
-
const i = [];
|
|
4
|
-
async function p() {
|
|
5
|
-
const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, t = await window.originalFetch(e, {
|
|
6
|
-
method: "POST",
|
|
7
|
-
credentials: "include"
|
|
8
|
-
});
|
|
9
|
-
if (!t.ok)
|
|
10
|
-
throw new Error("Error al refrescar token, status " + t.status);
|
|
11
|
-
return "Token refreshed";
|
|
12
|
-
}
|
|
13
|
-
window.fetch = async function(o, e) {
|
|
14
|
-
const t = typeof o == "string" ? o : o.toString();
|
|
15
|
-
if (console.log("URL petición:", t), t.includes("/api-auth/"))
|
|
16
|
-
return window.originalFetch(o, e);
|
|
17
|
-
e = e || {};
|
|
18
|
-
const u = sessionStorage.getItem("user_token");
|
|
19
|
-
e.headers = {
|
|
20
|
-
...e.headers,
|
|
21
|
-
...u ? { Authorization: u } : {}
|
|
22
|
-
};
|
|
23
|
-
try {
|
|
24
|
-
const c = `${window.location.protocol}//${window.location.host}/`, r = await window.originalFetch(o, e);
|
|
25
|
-
if (r.status !== 401) {
|
|
26
|
-
const n = await r.clone().text();
|
|
27
|
-
if (!n.includes("Signature has expired"))
|
|
28
|
-
return r;
|
|
29
|
-
if (n.includes("Invalid or expired token"))
|
|
30
|
-
return sessionStorage.removeItem("user_token"), setTimeout(() => {
|
|
31
|
-
window.location.href = c;
|
|
32
|
-
}, 1e3), r;
|
|
33
|
-
}
|
|
34
|
-
return new Promise((w, n) => {
|
|
35
|
-
i.push({ input: o, init: e, resolve: w, reject: n }), l || (l = !0, h = p(), h.then(() => {
|
|
36
|
-
i.forEach(({ input: a, init: s, resolve: d, reject: f }) => {
|
|
37
|
-
const g = {
|
|
38
|
-
...s,
|
|
39
|
-
headers: { ...s.headers, Authorization: sessionStorage.getItem("user_token") }
|
|
40
|
-
};
|
|
41
|
-
window.originalFetch(a, g).then(d).catch(f);
|
|
42
|
-
});
|
|
43
|
-
}).catch((a) => {
|
|
44
|
-
i.forEach(({ reject: s }) => s(a));
|
|
45
|
-
}).finally(() => {
|
|
46
|
-
i.length = 0, l = !1, h = null;
|
|
47
|
-
}));
|
|
48
|
-
});
|
|
49
|
-
} catch (c) {
|
|
50
|
-
return Promise.reject(c);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const k = {};
|
|
54
|
-
export {
|
|
55
|
-
k as default
|
|
56
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
window.originalFetch = window.fetch.bind(window);
|
|
2
|
-
let l = !1, h = null;
|
|
3
|
-
const c = [];
|
|
4
|
-
async function k() {
|
|
5
|
-
const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, t = await window.originalFetch(e, {
|
|
6
|
-
method: "POST",
|
|
7
|
-
credentials: "include"
|
|
8
|
-
});
|
|
9
|
-
if (!t.ok)
|
|
10
|
-
throw new Error("Error al refrescar token, status " + t.status);
|
|
11
|
-
return console.warn("Token refrescado"), "Token refreshed";
|
|
12
|
-
}
|
|
13
|
-
window.fetch = async function(o, e) {
|
|
14
|
-
const t = typeof o == "string" ? o : o.toString();
|
|
15
|
-
if (console.log("Petición fetchInterceptor Librería:", t), t.includes("/api-auth/"))
|
|
16
|
-
return window.originalFetch(o, e);
|
|
17
|
-
e = e || {};
|
|
18
|
-
const u = sessionStorage.getItem("user_token");
|
|
19
|
-
e.headers = {
|
|
20
|
-
...e.headers,
|
|
21
|
-
...u ? { Authorization: u } : {}
|
|
22
|
-
};
|
|
23
|
-
try {
|
|
24
|
-
const i = `${window.location.protocol}//${window.location.host}/`, r = await window.originalFetch(o, e);
|
|
25
|
-
if (r.status !== 401) {
|
|
26
|
-
const n = await r.clone().text();
|
|
27
|
-
if (!n.includes("Signature has expired"))
|
|
28
|
-
return r;
|
|
29
|
-
if (n.includes("Invalid or expired token"))
|
|
30
|
-
return console.warn("El token expiró"), sessionStorage.removeItem("user_token"), setTimeout(() => {
|
|
31
|
-
window.location.href = i;
|
|
32
|
-
}, 1e3), r;
|
|
33
|
-
}
|
|
34
|
-
return new Promise((w, n) => {
|
|
35
|
-
c.push({ input: o, init: e, resolve: w, reject: n }), l || (l = !0, h = k(), h.then(() => {
|
|
36
|
-
c.forEach(({ input: a, init: s, resolve: d, reject: f }) => {
|
|
37
|
-
const g = {
|
|
38
|
-
...s,
|
|
39
|
-
headers: { ...s.headers, Authorization: sessionStorage.getItem("user_token") }
|
|
40
|
-
};
|
|
41
|
-
window.originalFetch(a, g).then(d).catch(f);
|
|
42
|
-
});
|
|
43
|
-
}).catch((a) => {
|
|
44
|
-
c.forEach(({ reject: s }) => s(a));
|
|
45
|
-
}).finally(() => {
|
|
46
|
-
c.length = 0, l = !1, h = null;
|
|
47
|
-
}));
|
|
48
|
-
});
|
|
49
|
-
} catch (i) {
|
|
50
|
-
return Promise.reject(i);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const p = {};
|
|
54
|
-
export {
|
|
55
|
-
p as default
|
|
56
|
-
};
|