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

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,12 @@
1
- import { jsx as S } from "react/jsx-runtime";
2
- import { useState as T, useEffect as b } from "react";
1
+ import { jsx as b } from "react/jsx-runtime";
2
+ import { useState as S, useEffect as T } from "react";
3
3
  import { useLocation as g, Outlet as y } from "react-router-dom";
4
4
  import { j as _ } from "../../index-CuHybtft.js";
5
- const I = () => {
6
- const [k, t] = T(!1), p = g(), s = `${window.location.protocol}//${window.location.host}/`, v = async () => {
5
+ const R = () => {
6
+ const [k, t] = S(!1), w = g(), s = `${window.location.protocol}//${window.location.host}/`;
7
+ if (`${window.location.host}`.includes("localhost"))
8
+ return console.warn("ProtectedRoute is disabled in the local development environment."), null;
9
+ const v = async () => {
7
10
  if ((await fetch(`${s}api-auth/auth/refresh_token/`, {
8
11
  method: "POST",
9
12
  headers: {
@@ -13,7 +16,7 @@ const I = () => {
13
16
  })).ok)
14
17
  return !0;
15
18
  throw new Error("Error al refrescar token de Microsoft");
16
- }, w = async (d) => {
19
+ }, p = async (d) => {
17
20
  const l = await fetch(`${s}api-auth/users/role_by_user/`, {
18
21
  method: "POST",
19
22
  headers: {
@@ -23,10 +26,10 @@ const I = () => {
23
26
  body: JSON.stringify({ id_usuario: d })
24
27
  });
25
28
  if (l.ok)
26
- return (await l.json()).roles.map((a) => a.id_rol);
29
+ return (await l.json()).roles.map((n) => n.id_rol);
27
30
  throw new Error("Error al obtener los roles del usuario");
28
31
  };
29
- return b(() => {
32
+ return T(() => {
30
33
  (async () => {
31
34
  try {
32
35
  if ((await fetch(`${s}api-auth/auth/validate_jwt/`, {
@@ -36,16 +39,16 @@ const I = () => {
36
39
  },
37
40
  credentials: "include"
38
41
  })).ok) {
39
- const n = sessionStorage.getItem("user_token");
40
- if (n) {
41
- const r = _(n), a = r.datos_basicos.servicios.map((e) => e.url).filter((e) => !!e), i = p.pathname, c = a.map(
42
+ const a = sessionStorage.getItem("user_token");
43
+ if (a) {
44
+ const r = _(a), n = r.datos_basicos.servicios.map((e) => e.url).filter((e) => !!e), i = w.pathname, c = n.map(
42
45
  (e) => e.startsWith("/") ? e : `/${e}`
43
- ), h = i.startsWith("/") ? i : `/${i}`, f = c.some(
46
+ ), h = i.startsWith("/") ? i : `/${i}`, u = c.some(
44
47
  (e) => h.startsWith(e)
45
- ), u = await w(r.datos_basicos.id_busuario), m = r.datos_basicos.servicios.some(
46
- (e) => u.includes(e.id_rol)
48
+ ), f = await p(r.datos_basicos.id_busuario), m = r.datos_basicos.servicios.some(
49
+ (e) => f.includes(e.id_rol)
47
50
  );
48
- f && m ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
51
+ u && m ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
49
52
  } else
50
53
  t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
51
54
  } else
@@ -55,14 +58,14 @@ const I = () => {
55
58
  if (await v()) {
56
59
  const r = sessionStorage.getItem("user_token");
57
60
  if (r) {
58
- const a = _(r), i = a.datos_basicos.servicios.map((o) => o.url).filter((o) => !!o), c = p.pathname, h = i.map(
61
+ const n = _(r), i = n.datos_basicos.servicios.map((o) => o.url).filter((o) => !!o), c = w.pathname, h = i.map(
59
62
  (o) => o.startsWith("/") ? o : `/${o}`
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
+ ), u = c.startsWith("/") ? c : `/${c}`, f = h.some(
64
+ (o) => u.startsWith(o)
65
+ ), m = await p(n.datos_basicos.id_busuario), e = n.datos_basicos.servicios.some(
63
66
  (o) => m.includes(o.id_rol)
64
67
  );
65
- u && e ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
68
+ f && e ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
66
69
  } else
67
70
  t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
68
71
  } else
@@ -72,8 +75,8 @@ const I = () => {
72
75
  }
73
76
  }
74
77
  })();
75
- }, []), k ? /* @__PURE__ */ S(y, {}) : null;
78
+ }, []), k ? /* @__PURE__ */ b(y, {}) : null;
76
79
  };
77
80
  export {
78
- I as ProtectedRoute
81
+ R as ProtectedRoute
79
82
  };
@@ -2,7 +2,10 @@ import { jsx as c } from "react/jsx-runtime";
2
2
  import { useState as l, useEffect as d } from "react";
3
3
  import { useNavigate as h, Outlet as u } from "react-router-dom";
4
4
  const k = () => {
5
- const [o, t] = l(!1), r = h(), e = `${window.location.protocol}//${window.location.host}/`, s = async () => {
5
+ const [t, o] = l(!1), n = h(), e = `${window.location.protocol}//${window.location.host}/`;
6
+ if (`${window.location.host}`.includes("localhost"))
7
+ return console.warn("ProtectedRoute is disabled in the local development environment."), null;
8
+ const r = async () => {
6
9
  if ((await fetch(`${e}api-auth/auth/refresh_token/`, {
7
10
  method: "POST",
8
11
  headers: {
@@ -23,10 +26,10 @@ const k = () => {
23
26
  },
24
27
  credentials: "include"
25
28
  })).ok)
26
- t(!0);
29
+ o(!0);
27
30
  else
28
31
  try {
29
- if (await s())
32
+ if (await r())
30
33
  (await fetch(
31
34
  `${e}api-auth/auth/validate_jwt/`,
32
35
  {
@@ -36,7 +39,7 @@ const k = () => {
36
39
  },
37
40
  credentials: "include"
38
41
  }
39
- )).ok ? t(!0) : (sessionStorage.removeItem("user_token"), window.location.href = e);
42
+ )).ok ? o(!0) : (sessionStorage.removeItem("user_token"), window.location.href = e);
40
43
  else
41
44
  throw new Error("No se pudo refrescar el token.");
42
45
  } catch {
@@ -46,7 +49,7 @@ const k = () => {
46
49
  sessionStorage.removeItem("user_token"), window.location.href = e;
47
50
  }
48
51
  })();
49
- }, [r]), o ? /* @__PURE__ */ c(u, {}) : null;
52
+ }, [n]), t ? /* @__PURE__ */ c(u, {}) : null;
50
53
  };
51
54
  export {
52
55
  k as UserRoute
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-4",
5
+ "version": "1.7.18.pre-5",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {