react-ecosistema-unp 1.7.18 → 1.7.19

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