react-ecosistema-unp 1.8.0-pre.13 → 1.8.0-pre.14
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 w } from "react/jsx-runtime";
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useLocation as
|
|
4
|
-
import
|
|
2
|
+
import { useState as S, useEffect as p } from "react";
|
|
3
|
+
import { useLocation as _, Outlet as v } from "react-router-dom";
|
|
4
|
+
import I from "../fingerprint/fingerprintService.js";
|
|
5
5
|
const E = () => {
|
|
6
|
-
const [
|
|
7
|
-
const m = await
|
|
6
|
+
const [k, o] = S(!1), d = _(), a = `${window.location.protocol}//${window.location.host}/`, l = `${window.location.host}`, g = async () => {
|
|
7
|
+
const m = await I.getFingerprint(), h = localStorage.getItem("refresh_token"), s = await fetch(`${a}api-auth/auth/refresh_token/`, {
|
|
8
8
|
method: "POST",
|
|
9
9
|
headers: {
|
|
10
10
|
"Content-Type": "application/json",
|
|
@@ -17,49 +17,49 @@ const E = () => {
|
|
|
17
17
|
})
|
|
18
18
|
});
|
|
19
19
|
if (s.ok) {
|
|
20
|
-
const
|
|
21
|
-
return localStorage.setItem("access_token",
|
|
20
|
+
const n = await s.json(), i = n.access_token, r = n.refresh_token;
|
|
21
|
+
return localStorage.setItem("access_token", i), localStorage.setItem("refresh_token", r), !0;
|
|
22
22
|
} else
|
|
23
23
|
throw new Error("Error al refrescar token de Microsoft");
|
|
24
24
|
};
|
|
25
|
-
return
|
|
25
|
+
return p(() => {
|
|
26
26
|
const m = async () => {
|
|
27
27
|
try {
|
|
28
28
|
if (localStorage.getItem("access_token")) {
|
|
29
29
|
const s = localStorage.getItem("auth_state");
|
|
30
30
|
if (s) {
|
|
31
|
-
const
|
|
31
|
+
const i = JSON.parse(s).user.servicios.map((e) => e.url).filter((e) => !!e), r = d.pathname, c = i.map(
|
|
32
32
|
(e) => e.startsWith("/") ? e : `/${e}`
|
|
33
|
-
), f =
|
|
34
|
-
|
|
33
|
+
), f = r.startsWith("/") ? r : `/${r}`;
|
|
34
|
+
c.some(
|
|
35
35
|
(e) => f.startsWith(e)
|
|
36
|
-
) ? o(!0) : (console.warn("No hay match con los roles del usuario"), o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href =
|
|
36
|
+
) ? o(!0) : (console.warn("No hay match con los roles del usuario"), o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = a);
|
|
37
37
|
} else
|
|
38
|
-
o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href =
|
|
38
|
+
o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = a;
|
|
39
39
|
} else
|
|
40
40
|
throw new Error("Token inválido");
|
|
41
41
|
} catch {
|
|
42
42
|
try {
|
|
43
|
-
if (await
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
43
|
+
if (await g()) {
|
|
44
|
+
const n = localStorage.getItem("auth_state");
|
|
45
|
+
if (n) {
|
|
46
|
+
const r = JSON.parse(n).user.servicios.map((t) => t.url).filter((t) => !!t), c = d.pathname, f = r.map(
|
|
47
47
|
(t) => t.startsWith("/") ? t : `/${t}`
|
|
48
|
-
), u =
|
|
48
|
+
), u = c.startsWith("/") ? c : `/${c}`;
|
|
49
49
|
f.some(
|
|
50
50
|
(t) => u.startsWith(t)
|
|
51
|
-
) ? o(!0) : (o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href =
|
|
51
|
+
) ? o(!0) : (o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = a);
|
|
52
52
|
} else
|
|
53
|
-
o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href =
|
|
53
|
+
o(!1), sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = a;
|
|
54
54
|
} else
|
|
55
55
|
throw new Error("No se pudo refrescar el token.");
|
|
56
56
|
} catch {
|
|
57
|
-
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href =
|
|
57
|
+
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = a, o(!1);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
|
|
62
|
-
}, []),
|
|
61
|
+
l.includes("ecosistemadesarrollo") || l.includes("ecosistemapruebas") || l.includes("ecosistemaprov") || l.includes("ecosistema") ? m() : (console.warn("ProtectedRoute is disabled in the local development environment."), o(!0));
|
|
62
|
+
}, []), k ? /* @__PURE__ */ w(v, {}) : null;
|
|
63
63
|
};
|
|
64
64
|
export {
|
|
65
65
|
E as ProtectedRoute
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as d, useEffect as
|
|
3
|
-
import { useNavigate as
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
const [
|
|
7
|
-
if (
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { useState as d, useEffect as u } from "react";
|
|
3
|
+
import { useNavigate as w, Outlet as k } from "react-router-dom";
|
|
4
|
+
import p from "../fingerprint/fingerprintService.js";
|
|
5
|
+
const I = () => {
|
|
6
|
+
const [c, e] = d(!1), i = w(), t = `${window.location.protocol}//${window.location.host}/`, a = `${window.location.host}`;
|
|
7
|
+
if (a.includes("localhost"))
|
|
8
8
|
return console.warn("ProtectedRoute is disabled in the local development environment."), null;
|
|
9
9
|
const l = async () => {
|
|
10
|
-
const
|
|
11
|
-
if ((await fetch(`${t}api-auth/auth/refresh_token/`, {
|
|
10
|
+
const r = await p.getFingerprint(), n = localStorage.getItem("refresh_token"), o = await fetch(`${t}api-auth/auth/refresh_token/`, {
|
|
12
11
|
method: "POST",
|
|
13
12
|
headers: {
|
|
14
13
|
"Content-Type": "application/json",
|
|
15
|
-
"X-Fingerprint":
|
|
14
|
+
"X-Fingerprint": r
|
|
16
15
|
},
|
|
17
16
|
credentials: "include",
|
|
18
17
|
body: JSON.stringify({
|
|
19
|
-
refresh:
|
|
18
|
+
refresh: n
|
|
20
19
|
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
});
|
|
21
|
+
if (o.ok) {
|
|
22
|
+
const s = await o.json(), f = s.access_token, h = s.refresh_token;
|
|
23
|
+
return localStorage.setItem("access_token", f), localStorage.setItem("refresh_token", h), !0;
|
|
24
|
+
} else
|
|
25
|
+
throw new Error("Error al refrescar token de Microsoft");
|
|
24
26
|
};
|
|
25
|
-
return
|
|
26
|
-
const
|
|
27
|
+
return u(() => {
|
|
28
|
+
const r = async () => {
|
|
27
29
|
try {
|
|
28
30
|
if (localStorage.getItem("access_token"))
|
|
29
31
|
e(!0);
|
|
@@ -49,9 +51,9 @@ const S = () => {
|
|
|
49
51
|
sessionStorage.removeItem("user_token"), localStorage.removeItem("auth_state"), localStorage.removeItem("access_token"), window.location.href = t, e(!1);
|
|
50
52
|
}
|
|
51
53
|
};
|
|
52
|
-
|
|
53
|
-
}, [i]),
|
|
54
|
+
a.includes("localhost") ? (console.warn("ProtectedRoute is disabled in the local development environment."), e(!0)) : r();
|
|
55
|
+
}, [i]), c ? /* @__PURE__ */ m(k, {}) : null;
|
|
54
56
|
};
|
|
55
57
|
export {
|
|
56
|
-
|
|
58
|
+
I as UserRoute
|
|
57
59
|
};
|