react-ecosistema-unp 1.7.1-8.pre-2 → 1.7.1-8.pre-3
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.
|
@@ -3,7 +3,7 @@ import { useState as T, useEffect as b } from "react";
|
|
|
3
3
|
import { useNavigate as y, useLocation as U, Outlet as $ } from "react-router-dom";
|
|
4
4
|
import { j as _ } from "../../index-CuHybtft.js";
|
|
5
5
|
const W = () => {
|
|
6
|
-
const [k,
|
|
6
|
+
const [k, t] = T(!1), v = y(), p = U(), s = `${window.location.protocol}//${window.location.host}/`, g = async () => {
|
|
7
7
|
if ((await fetch(`${s}api-auth/auth/refresh_token/`, {
|
|
8
8
|
method: "POST",
|
|
9
9
|
headers: {
|
|
@@ -23,7 +23,7 @@ const W = () => {
|
|
|
23
23
|
body: JSON.stringify({ id_usuario: d })
|
|
24
24
|
});
|
|
25
25
|
if (l.ok)
|
|
26
|
-
return (await l.json()).roles.map((
|
|
26
|
+
return (await l.json()).roles.map((a) => a.id_rol);
|
|
27
27
|
throw new Error("Error al obtener los roles del usuario");
|
|
28
28
|
};
|
|
29
29
|
return b(() => {
|
|
@@ -38,37 +38,37 @@ const W = () => {
|
|
|
38
38
|
})).ok) {
|
|
39
39
|
const n = sessionStorage.getItem("user_token");
|
|
40
40
|
if (n) {
|
|
41
|
-
const
|
|
41
|
+
const r = _(n), a = r.datos_basicos.servicios.map((e) => e.url).filter((e) => !!e), i = p.pathname, c = a.map(
|
|
42
42
|
(e) => e.startsWith("/") ? e : `/${e}`
|
|
43
|
-
), h = i.startsWith("/") ? i : `/${i}`,
|
|
43
|
+
), h = i.startsWith("/") ? i : `/${i}`, f = c.some(
|
|
44
44
|
(e) => h.startsWith(e)
|
|
45
|
-
),
|
|
46
|
-
(e) =>
|
|
45
|
+
), u = await w(r.datos_basicos.id_busuario), m = r.datos_basicos.servicios.some(
|
|
46
|
+
(e) => u.includes(e.id_rol)
|
|
47
47
|
);
|
|
48
|
-
|
|
48
|
+
f && m ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
|
|
49
49
|
} else
|
|
50
|
-
|
|
50
|
+
t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
|
|
51
51
|
} else
|
|
52
52
|
throw new Error("Token inválido");
|
|
53
53
|
} catch {
|
|
54
54
|
try {
|
|
55
55
|
if (await g()) {
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
const
|
|
56
|
+
const r = sessionStorage.getItem("user_token");
|
|
57
|
+
if (r) {
|
|
58
|
+
const a = _(r), i = a.datos_basicos.servicios.map((o) => o.url).filter((o) => !!o), c = p.pathname, h = i.map(
|
|
59
59
|
(o) => o.startsWith("/") ? o : `/${o}`
|
|
60
|
-
),
|
|
61
|
-
(o) =>
|
|
62
|
-
), m = await w(
|
|
60
|
+
), f = c.startsWith("/") ? c : `/${c}`, u = h.some(
|
|
61
|
+
(o) => f.startsWith(o)
|
|
62
|
+
), m = await w(a.datos_basicos.id_busuario), e = a.datos_basicos.servicios.some(
|
|
63
63
|
(o) => m.includes(o.id_rol)
|
|
64
64
|
);
|
|
65
|
-
|
|
65
|
+
u && e ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
|
|
66
66
|
} else
|
|
67
|
-
|
|
67
|
+
t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
|
|
68
68
|
} else
|
|
69
69
|
throw new Error("No se pudo refrescar el token.");
|
|
70
70
|
} catch {
|
|
71
|
-
sessionStorage.removeItem("user_token"), window.location.href = s;
|
|
71
|
+
sessionStorage.removeItem("user_token"), window.location.href = s, t(!1);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
})();
|