react-ecosistema-unp 1.6.0-pre.0 → 1.6.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/lib/main.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
@@ -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
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as a } from "react/jsx-runtime";
|
|
2
2
|
import { useState as i, useEffect as s } from "react";
|
|
3
3
|
import { useNavigate as l, Outlet as c } from "react-router-dom";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import "./fetchInterceptor.js";
|
|
5
|
+
const w = () => {
|
|
6
|
+
const [e, r] = i(!1), n = l(), o = `${window.location.protocol}//${window.location.host}/`;
|
|
6
7
|
return s(() => {
|
|
7
8
|
(async () => {
|
|
8
9
|
try {
|
|
@@ -16,7 +17,7 @@ const h = () => {
|
|
|
16
17
|
credentials: "include"
|
|
17
18
|
}
|
|
18
19
|
)).ok)
|
|
19
|
-
|
|
20
|
+
r(!0);
|
|
20
21
|
else
|
|
21
22
|
return window.location.href = o;
|
|
22
23
|
} catch (t) {
|
|
@@ -24,8 +25,8 @@ const h = () => {
|
|
|
24
25
|
} finally {
|
|
25
26
|
}
|
|
26
27
|
})();
|
|
27
|
-
}, [
|
|
28
|
+
}, [n]), e ? /* @__PURE__ */ a(c, {}) : null;
|
|
28
29
|
};
|
|
29
30
|
export {
|
|
30
|
-
|
|
31
|
+
w as UserRoute
|
|
31
32
|
};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
window.originalFetch = window.fetch.bind(window);
|
|
2
|
-
let
|
|
3
|
-
const
|
|
4
|
-
async function
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
);
|
|
12
|
-
if (!
|
|
13
|
-
throw new Error("
|
|
14
|
-
const
|
|
15
|
-
return sessionStorage.setItem("user_token", `Bearer ${
|
|
2
|
+
let i = !1, h = null;
|
|
3
|
+
const s = [];
|
|
4
|
+
async function k() {
|
|
5
|
+
const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, o = await window.originalFetch(e, {
|
|
6
|
+
method: "POST",
|
|
7
|
+
credentials: "include"
|
|
8
|
+
});
|
|
9
|
+
if (!o.ok)
|
|
10
|
+
throw new Error("Error al refrescar token, status " + o.status);
|
|
11
|
+
const n = await o.json();
|
|
12
|
+
if (!n.token)
|
|
13
|
+
throw new Error("No se recibió token en la respuesta de refresh");
|
|
14
|
+
const t = n.token;
|
|
15
|
+
return sessionStorage.setItem("user_token", `Bearer ${t}`), `Bearer ${t}`;
|
|
16
16
|
}
|
|
17
|
-
window.fetch = async function(
|
|
17
|
+
window.fetch = async function(r, e) {
|
|
18
|
+
const o = typeof r == "string" ? r : r.toString();
|
|
19
|
+
if (o.includes("/auth/refresh_token") || o.includes("/auth/validate"))
|
|
20
|
+
return window.originalFetch(r, e);
|
|
18
21
|
e = e || {};
|
|
19
22
|
const n = sessionStorage.getItem("user_token");
|
|
20
23
|
e.headers = {
|
|
@@ -22,20 +25,23 @@ window.fetch = async function(t, e) {
|
|
|
22
25
|
...n ? { Authorization: n } : {}
|
|
23
26
|
};
|
|
24
27
|
try {
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
28
|
+
const t = await window.originalFetch(r, e);
|
|
29
|
+
return t.status !== 401 ? t : new Promise((u, w) => {
|
|
30
|
+
s.push({ input: r, init: e, resolve: u, reject: w }), i || (i = !0, h = k(), h.then((a) => {
|
|
31
|
+
s.forEach(({ input: c, init: l, resolve: d, reject: f }) => {
|
|
32
|
+
const g = {
|
|
33
|
+
...l,
|
|
34
|
+
headers: { ...l.headers, Authorization: a }
|
|
35
|
+
};
|
|
36
|
+
window.originalFetch(c, g).then(d).catch(f);
|
|
31
37
|
});
|
|
32
|
-
}).catch((
|
|
33
|
-
|
|
38
|
+
}).catch((a) => {
|
|
39
|
+
s.forEach(({ reject: c }) => c(a));
|
|
34
40
|
}).finally(() => {
|
|
35
|
-
|
|
41
|
+
s.length = 0, i = !1, h = null;
|
|
36
42
|
}));
|
|
37
43
|
});
|
|
38
|
-
} catch (
|
|
39
|
-
return Promise.reject(
|
|
44
|
+
} catch (t) {
|
|
45
|
+
return Promise.reject(t);
|
|
40
46
|
}
|
|
41
47
|
};
|