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