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

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