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

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