react-ecosistema-unp 1.6.0-pre.6 → 1.6.0-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,9 +1,10 @@
1
- import { jsx as h } from "react/jsx-runtime";
2
- import { useState as m, useEffect as p } from "react";
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { useState as h, useEffect as p } from "react";
3
3
  import { useNavigate as w, useLocation as u, Outlet as k } from "react-router-dom";
4
4
  import { j as v } from "../../index-CuHybtft.js";
5
- const V = () => {
6
- const [i, e] = m(!1), r = w(), c = u(), o = `${window.location.protocol}//${window.location.host}/`;
5
+ import "./fetchInterceptor.js";
6
+ const W = () => {
7
+ const [i, e] = h(!1), r = w(), c = u(), o = `${window.location.protocol}//${window.location.host}/`;
7
8
  return p(() => {
8
9
  (async () => {
9
10
  try {
@@ -34,8 +35,8 @@ const V = () => {
34
35
  } finally {
35
36
  }
36
37
  })();
37
- }, [r]), i ? /* @__PURE__ */ h(k, {}) : null;
38
+ }, [r]), i ? /* @__PURE__ */ m(k, {}) : null;
38
39
  };
39
40
  export {
40
- V as ProtectedRoute
41
+ W as ProtectedRoute
41
42
  };
@@ -2,22 +2,22 @@ window.originalFetch = window.fetch.bind(window);
2
2
  let c = !1, h = null;
3
3
  const s = [];
4
4
  async function k() {
5
- const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, o = await window.originalFetch(e, {
5
+ const e = `${`${window.location.protocol}//${window.location.host}/`}api-auth/auth/refresh_token/`, r = await window.originalFetch(e, {
6
6
  method: "POST",
7
7
  credentials: "include"
8
8
  });
9
- if (!o.ok)
10
- throw new Error("Error al refrescar token, status " + o.status);
11
- const n = await o.json();
9
+ if (!r.ok)
10
+ throw new Error("Error al refrescar token, status " + r.status);
11
+ const n = await r.json();
12
12
  if (!n.token)
13
13
  throw new Error("No se recibió token en la respuesta de refresh");
14
14
  const t = n.token;
15
15
  return sessionStorage.setItem("user_token", `${t}`), `${t}`;
16
16
  }
17
- window.fetch = async function(r, e) {
18
- const o = typeof r == "string" ? r : r.toString();
19
- if (o.includes("/auth/refresh_token") || o.includes("/auth/validate"))
20
- return window.originalFetch(r, e);
17
+ window.fetch = async function(o, e) {
18
+ const r = typeof o == "string" ? o : o.toString();
19
+ if (console.log("URL petición:", r), r.includes("/api-auth/"))
20
+ return window.originalFetch(o, e);
21
21
  e = e || {};
22
22
  const n = sessionStorage.getItem("user_token");
23
23
  e.headers = {
@@ -25,13 +25,13 @@ window.fetch = async function(r, e) {
25
25
  ...n ? { Authorization: n } : {}
26
26
  };
27
27
  try {
28
- const t = await window.originalFetch(r, e);
29
- return t.status !== 401 && !(await t.text()).includes("Signature has expired") ? t : new Promise((u, w) => {
30
- s.push({ input: r, init: e, resolve: u, reject: w }), c || (c = !0, h = k(), h.then((a) => {
31
- s.forEach(({ input: i, init: l, resolve: d, reject: f }) => {
28
+ const t = await window.originalFetch(o, e);
29
+ return console.log("Response petición:", t), t.status !== 401 && !(await t.text()).includes("Signature has expired") ? t : new Promise((l, w) => {
30
+ s.push({ input: o, init: e, resolve: l, reject: w }), c || (c = !0, h = k(), h.then((a) => {
31
+ s.forEach(({ input: i, init: u, resolve: d, reject: f }) => {
32
32
  const g = {
33
- ...l,
34
- headers: { ...l.headers, Authorization: a }
33
+ ...u,
34
+ headers: { ...u.headers, Authorization: a }
35
35
  };
36
36
  window.originalFetch(i, g).then(d).catch(f);
37
37
  });
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.6.0-pre.6",
5
+ "version": "1.6.0-pre.8",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {