react-ecosistema-unp 1.7.16-pre.0 → 1.7.16

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