react-ecosistema-unp 1.8.0-pre.12 → 1.8.0-pre.13

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