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

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,13 +1,10 @@
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 () => {
10
- if ((await fetch(`${s}api-auth/auth/refresh_token/`, {
6
+ const [k, s] = g(!1), w = T(), t = `${window.location.protocol}//${window.location.host}/`, v = `${window.location.host}`, b = async () => {
7
+ if ((await fetch(`${t}api-auth/auth/refresh_token/`, {
11
8
  method: "POST",
12
9
  headers: {
13
10
  "Content-Type": "application/json"
@@ -16,23 +13,23 @@ 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(`${t}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
- if ((await fetch(`${s}api-auth/auth/validate_jwt/`, {
32
+ if ((await fetch(`${t}api-auth/auth/validate_jwt/`, {
36
33
  method: "POST",
37
34
  headers: {
38
35
  "Content-Type": "application/json"
@@ -48,14 +45,14 @@ const R = () => {
48
45
  ), f = await p(r.datos_basicos.id_busuario), m = r.datos_basicos.servicios.some(
49
46
  (e) => f.includes(e.id_rol)
50
47
  );
51
- u && m ? t(!0) : (t(!1), sessionStorage.removeItem("user_token"), window.location.href = s);
48
+ u && m ? s(!0) : (s(!1), sessionStorage.removeItem("user_token"), window.location.href = t);
52
49
  } else
53
- t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
50
+ s(!1), sessionStorage.removeItem("user_token"), window.location.href = t;
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(
@@ -65,17 +62,18 @@ const R = () => {
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
+ f && e ? s(!0) : (s(!1), sessionStorage.removeItem("user_token"), window.location.href = t);
69
66
  } else
70
- t(!1), sessionStorage.removeItem("user_token"), window.location.href = s;
67
+ s(!1), sessionStorage.removeItem("user_token"), window.location.href = t;
71
68
  } else
72
69
  throw new Error("No se pudo refrescar el token.");
73
70
  } catch {
74
- sessionStorage.removeItem("user_token"), window.location.href = s, t(!1);
71
+ sessionStorage.removeItem("user_token"), window.location.href = t, s(!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."), s(!0)) : l();
76
+ }, []), k ? /* @__PURE__ */ S(U, {}) : null;
79
77
  };
80
78
  export {
81
79
  R as ProtectedRoute
@@ -1,12 +1,12 @@
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, e] = d(!1), s = u(), o = `${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 () => {
9
- if ((await fetch(`${e}api-auth/auth/refresh_token/`, {
8
+ const a = async () => {
9
+ if ((await fetch(`${o}api-auth/auth/refresh_token/`, {
10
10
  method: "POST",
11
11
  headers: {
12
12
  "Content-Type": "application/json"
@@ -16,22 +16,22 @@ 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
- if ((await fetch(`${e}api-auth/auth/validate_jwt/`, {
22
+ if ((await fetch(`${o}api-auth/auth/validate_jwt/`, {
23
23
  method: "POST",
24
24
  headers: {
25
25
  "Content-Type": "application/json"
26
26
  },
27
27
  credentials: "include"
28
28
  })).ok)
29
- o(!0);
29
+ e(!0);
30
30
  else
31
31
  try {
32
- if (await r())
32
+ if (await a())
33
33
  (await fetch(
34
- `${e}api-auth/auth/validate_jwt/`,
34
+ `${o}api-auth/auth/validate_jwt/`,
35
35
  {
36
36
  method: "POST",
37
37
  headers: {
@@ -39,17 +39,18 @@ const k = () => {
39
39
  },
40
40
  credentials: "include"
41
41
  }
42
- )).ok ? o(!0) : (sessionStorage.removeItem("user_token"), window.location.href = e);
42
+ )).ok ? e(!0) : (sessionStorage.removeItem("user_token"), window.location.href = o, e(!1));
43
43
  else
44
44
  throw new Error("No se pudo refrescar el token.");
45
45
  } catch {
46
- sessionStorage.removeItem("user_token"), window.location.href = e;
46
+ sessionStorage.removeItem("user_token"), window.location.href = o, e(!1);
47
47
  }
48
48
  } catch {
49
- sessionStorage.removeItem("user_token"), window.location.href = e;
49
+ sessionStorage.removeItem("user_token"), window.location.href = o, e(!1);
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."), e(!0)) : 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-7",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {