react-ecosistema-unp 1.7.1-8.pre-2 → 1.7.1-8.pre-4

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,9 @@
1
1
  import { jsx as S } from "react/jsx-runtime";
2
2
  import { useState as T, useEffect as b } from "react";
3
- import { useNavigate as y, useLocation as U, Outlet as $ } from "react-router-dom";
3
+ import { useLocation as g, Outlet as y } from "react-router-dom";
4
4
  import { j as _ } from "../../index-CuHybtft.js";
5
- const W = () => {
6
- const [k, a] = T(!1), v = y(), p = U(), s = `${window.location.protocol}//${window.location.host}/`, g = async () => {
5
+ const I = () => {
6
+ const [k, t] = T(!1), p = g(), s = `${window.location.protocol}//${window.location.host}/`, v = 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((r) => r.id_rol);
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,42 +38,42 @@ const W = () => {
38
38
  })).ok) {
39
39
  const n = sessionStorage.getItem("user_token");
40
40
  if (n) {
41
- const t = _(n), r = t.datos_basicos.servicios.map((e) => e.url).filter((e) => !!e), i = p.pathname, c = r.map(
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}`, u = c.some(
43
+ ), h = i.startsWith("/") ? i : `/${i}`, f = c.some(
44
44
  (e) => h.startsWith(e)
45
- ), f = await w(t.datos_basicos.id_busuario), m = t.datos_basicos.servicios.some(
46
- (e) => f.includes(e.id_rol)
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
- u && m ? a(!0) : (a(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
48
+ f && m ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
49
49
  } else
50
- a(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
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
- if (await g()) {
56
- const t = sessionStorage.getItem("user_token");
57
- if (t) {
58
- const r = _(t), i = r.datos_basicos.servicios.map((o) => o.url).filter((o) => !!o), c = p.pathname, h = i.map(
55
+ if (await v()) {
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
- ), u = c.startsWith("/") ? c : `/${c}`, f = h.some(
61
- (o) => u.startsWith(o)
62
- ), m = await w(r.datos_basicos.id_busuario), e = r.datos_basicos.servicios.some(
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
- f && e ? a(!0) : (a(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
65
+ u && e ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
66
66
  } else
67
- a(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
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
  })();
75
- }, [v]), k ? /* @__PURE__ */ S($, {}) : null;
75
+ }, []), k ? /* @__PURE__ */ S(y, {}) : null;
76
76
  };
77
77
  export {
78
- W as ProtectedRoute
78
+ I as ProtectedRoute
79
79
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "react-ecosistema-unp",
3
3
  "author": "Ecosistema de Información - Unidad Nacional de Protección",
4
4
  "private": false,
5
- "version": "1.7.18.pre-2",
5
+ "version": "1.7.18.pre-4",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {