react-ecosistema-unp 1.8.0-pre.11 → 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.
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Servicio para gestionar la generación del fingerprint del navegador.
|
|
3
|
+
* El fingerprint se usa para vincular tokens a dispositivos específicos.
|
|
4
|
+
*/
|
|
5
|
+
declare class FingerprintService {
|
|
6
|
+
private fpPromise;
|
|
7
|
+
private fingerprint;
|
|
8
|
+
/**
|
|
9
|
+
* Inicializa el agente de FingerprintJS y genera el fingerprint.
|
|
10
|
+
* @returns El identificador único del dispositivo (visitorId)
|
|
11
|
+
*/
|
|
12
|
+
initialize(): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Obtiene el fingerprint previamente generado.
|
|
15
|
+
* Si no existe, lo genera automáticamente.
|
|
16
|
+
* @returns El fingerprint del dispositivo
|
|
17
|
+
*/
|
|
18
|
+
getFingerprint(): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Obtiene el fingerprint de forma síncrona si ya fue generado.
|
|
21
|
+
* Útil cuando ya se ha llamado a initialize() previamente.
|
|
22
|
+
* @returns El fingerprint o null si no ha sido generado
|
|
23
|
+
*/
|
|
24
|
+
getFingerprintSync(): string | null;
|
|
25
|
+
}
|
|
26
|
+
declare const _default: FingerprintService;
|
|
27
|
+
export default _default;
|
|
@@ -1,61 +1,66 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useLocation as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 (
|
|
15
|
-
const
|
|
16
|
-
return localStorage.setItem("access_token",
|
|
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
|
|
21
|
-
const
|
|
25
|
+
return S(() => {
|
|
26
|
+
const m = async () => {
|
|
22
27
|
try {
|
|
23
28
|
if (localStorage.getItem("access_token")) {
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
const
|
|
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
|
-
),
|
|
33
|
+
), f = a.startsWith("/") ? a : `/${a}`;
|
|
29
34
|
n.some(
|
|
30
|
-
(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 =
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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") ?
|
|
57
|
-
}, []),
|
|
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
|
-
|
|
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
|
|
3
|
-
import { useNavigate as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
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
|
|
20
|
-
const
|
|
25
|
+
return f(() => {
|
|
26
|
+
const o = async () => {
|
|
21
27
|
try {
|
|
22
|
-
if ((
|
|
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
|
|
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
|
-
|
|
53
|
-
}, [
|
|
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
|
-
|
|
56
|
+
S as UserRoute
|
|
57
57
|
};
|