react-ecosistema-unp 1.6.0-pre.7 → 1.6.0-pre.8
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,9 +1,10 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { useState as h, useEffect as p } from "react";
|
|
3
3
|
import { useNavigate as w, useLocation as u, Outlet as k } from "react-router-dom";
|
|
4
4
|
import { j as v } from "../../index-CuHybtft.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import "./fetchInterceptor.js";
|
|
6
|
+
const W = () => {
|
|
7
|
+
const [i, e] = h(!1), r = w(), c = u(), o = `${window.location.protocol}//${window.location.host}/`;
|
|
7
8
|
return p(() => {
|
|
8
9
|
(async () => {
|
|
9
10
|
try {
|
|
@@ -34,8 +35,8 @@ const V = () => {
|
|
|
34
35
|
} finally {
|
|
35
36
|
}
|
|
36
37
|
})();
|
|
37
|
-
}, [r]), i ? /* @__PURE__ */
|
|
38
|
+
}, [r]), i ? /* @__PURE__ */ m(k, {}) : null;
|
|
38
39
|
};
|
|
39
40
|
export {
|
|
40
|
-
|
|
41
|
+
W as ProtectedRoute
|
|
41
42
|
};
|
|
@@ -11,12 +11,13 @@ async function k() {
|
|
|
11
11
|
const n = await r.json();
|
|
12
12
|
if (!n.token)
|
|
13
13
|
throw new Error("No se recibió token en la respuesta de refresh");
|
|
14
|
-
|
|
14
|
+
const t = n.token;
|
|
15
|
+
return sessionStorage.setItem("user_token", `${t}`), `${t}`;
|
|
15
16
|
}
|
|
16
|
-
window.fetch = async function(
|
|
17
|
-
const r = typeof
|
|
18
|
-
if (
|
|
19
|
-
return window.originalFetch(
|
|
17
|
+
window.fetch = async function(o, e) {
|
|
18
|
+
const r = typeof o == "string" ? o : o.toString();
|
|
19
|
+
if (console.log("URL petición:", r), r.includes("/api-auth/"))
|
|
20
|
+
return window.originalFetch(o, e);
|
|
20
21
|
e = e || {};
|
|
21
22
|
const n = sessionStorage.getItem("user_token");
|
|
22
23
|
e.headers = {
|
|
@@ -24,9 +25,9 @@ window.fetch = async function(t, e) {
|
|
|
24
25
|
...n ? { Authorization: n } : {}
|
|
25
26
|
};
|
|
26
27
|
try {
|
|
27
|
-
const
|
|
28
|
-
return
|
|
29
|
-
s.push({ input:
|
|
28
|
+
const t = await window.originalFetch(o, e);
|
|
29
|
+
return console.log("Response petición:", t), t.status !== 401 && !(await t.text()).includes("Signature has expired") ? t : new Promise((l, w) => {
|
|
30
|
+
s.push({ input: o, init: e, resolve: l, reject: w }), c || (c = !0, h = k(), h.then((a) => {
|
|
30
31
|
s.forEach(({ input: i, init: u, resolve: d, reject: f }) => {
|
|
31
32
|
const g = {
|
|
32
33
|
...u,
|
|
@@ -40,7 +41,7 @@ window.fetch = async function(t, e) {
|
|
|
40
41
|
s.length = 0, c = !1, h = null;
|
|
41
42
|
}));
|
|
42
43
|
});
|
|
43
|
-
} catch (
|
|
44
|
-
return Promise.reject(
|
|
44
|
+
} catch (t) {
|
|
45
|
+
return Promise.reject(t);
|
|
45
46
|
}
|
|
46
47
|
};
|