react-ecosistema-unp 1.8.0-pre.3 → 1.8.0-pre.5

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