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

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