@m4l/core 2.0.25 → 2.0.26
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.
- package/contexts/AuthContext/AuthContext.js +60 -88
- package/contexts/AuthContext/constants.d.ts +2 -0
- package/contexts/AuthContext/constants.js +8 -2
- package/contexts/AuthContext/helpers.d.ts +5 -0
- package/contexts/AuthContext/helpers.js +27 -0
- package/contexts/AuthContext/index.d.ts +1 -1
- package/contexts/AuthContext/types.d.ts +12 -0
- package/package.json +1 -1
|
@@ -1,122 +1,94 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { E as
|
|
4
|
-
import { E as
|
|
5
|
-
import {
|
|
6
|
-
import { u as
|
|
7
|
-
import { u as
|
|
1
|
+
import { jsx as C } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as U, useReducer as _, useEffect as f, useCallback as l } from "react";
|
|
3
|
+
import { i as p, E as n } from "./constants.js";
|
|
4
|
+
import { E as w } from "../../types/index.js";
|
|
5
|
+
import { J as I } from "./helpers.js";
|
|
6
|
+
import { u as L } from "../../hooks/useHostTools/index.js";
|
|
7
|
+
import { u as P } from "../../hooks/useNetwork/index.js";
|
|
8
|
+
import { u as x } from "../../hooks/useEnvironment/index.js";
|
|
8
9
|
import { u as N } from "../../hooks/useLocalStorageWithListener/index.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
user: null
|
|
15
|
-
}, C = (e, t) => {
|
|
16
|
-
switch (t.type) {
|
|
17
|
-
case "INITIALIZE":
|
|
18
|
-
return {
|
|
19
|
-
isAuthenticated: t.payload.isAuthenticated,
|
|
20
|
-
isInitialized: !0,
|
|
21
|
-
user: t.payload.user
|
|
22
|
-
};
|
|
23
|
-
case "LOGIN":
|
|
24
|
-
return {
|
|
25
|
-
...e,
|
|
26
|
-
isAuthenticated: !0,
|
|
27
|
-
user: t.payload.user
|
|
28
|
-
};
|
|
29
|
-
case "LOGOUT":
|
|
30
|
-
return {
|
|
31
|
-
...e,
|
|
32
|
-
isAuthenticated: !1,
|
|
33
|
-
user: null
|
|
34
|
-
};
|
|
35
|
-
default:
|
|
36
|
-
return e;
|
|
37
|
-
}
|
|
38
|
-
}, O = A(null);
|
|
39
|
-
function P(e) {
|
|
40
|
-
e({
|
|
41
|
-
type: r.Initial,
|
|
42
|
-
payload: {
|
|
43
|
-
isAuthenticated: !1,
|
|
44
|
-
user: null
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function j(e) {
|
|
49
|
-
const { children: t } = e, [m, i] = D(C, _), { events_add_listener: f } = S(), { networkOperation: o } = v(), { domain_token: p } = w(), [h, l] = N(
|
|
10
|
+
import { s as m } from "../../utils/setLocalStorage/index.js";
|
|
11
|
+
import { g as k } from "../../utils/getLocalStorage/index.js";
|
|
12
|
+
const z = U(null);
|
|
13
|
+
function b(g) {
|
|
14
|
+
const { children: h, isMicroFrontEnd: o = !1, loggedUser: c } = g, [E, s] = _(I, o ? { ...p, user: c, isAuthenticated: !0, isInitialized: !0 } : p), { events_add_listener: T } = L(), { networkOperation: t } = P(), { domain_token: d } = x(), [y, r] = N(
|
|
50
15
|
// Variable para saber si ha cambiado la session en otro navegador
|
|
51
16
|
"vSession",
|
|
52
17
|
(/* @__PURE__ */ new Date()).getTime() + ""
|
|
53
18
|
);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
19
|
+
f(() => {
|
|
20
|
+
const e = async () => {
|
|
21
|
+
t({
|
|
57
22
|
method: "GET",
|
|
58
23
|
endPoint: "auth/login",
|
|
59
24
|
parms: { user_data: !0 },
|
|
60
25
|
checkUnAuthorized: !1,
|
|
61
26
|
responseToCamelCase: !0
|
|
62
|
-
}).then((
|
|
63
|
-
|
|
64
|
-
type:
|
|
27
|
+
}).then((a) => {
|
|
28
|
+
s({
|
|
29
|
+
type: n.Initial,
|
|
65
30
|
payload: {
|
|
66
31
|
isAuthenticated: !0,
|
|
67
|
-
user:
|
|
32
|
+
user: a.user
|
|
68
33
|
}
|
|
69
|
-
}),
|
|
70
|
-
email:
|
|
34
|
+
}), k("userData", {
|
|
35
|
+
email: a.user.email,
|
|
71
36
|
remember: !0
|
|
72
|
-
})?.email !==
|
|
37
|
+
})?.email !== a.user.email && m("userData", { email: a.user.email }, !0);
|
|
73
38
|
}).catch(() => {
|
|
74
|
-
|
|
39
|
+
s({
|
|
40
|
+
type: n.Initial,
|
|
41
|
+
payload: {
|
|
42
|
+
isAuthenticated: !1,
|
|
43
|
+
user: null
|
|
44
|
+
}
|
|
45
|
+
});
|
|
75
46
|
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
47
|
+
};
|
|
48
|
+
o || e();
|
|
49
|
+
}, [t, y, o, c]);
|
|
50
|
+
const D = l(async (e, a, i) => {
|
|
51
|
+
await t({
|
|
80
52
|
endPoint: "auth/login",
|
|
81
53
|
method: "POST",
|
|
82
54
|
data: {
|
|
83
|
-
email:
|
|
84
|
-
password:
|
|
85
|
-
domain_token:
|
|
55
|
+
email: e,
|
|
56
|
+
password: a,
|
|
57
|
+
domain_token: d
|
|
86
58
|
},
|
|
87
59
|
responseToCamelCase: !0
|
|
88
|
-
}).then((
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
type:
|
|
60
|
+
}).then((v) => {
|
|
61
|
+
const A = v.data;
|
|
62
|
+
i ? m("userData", { email: e, remember: i }) : m("userData", { email: "", remember: i }), s({
|
|
63
|
+
type: n.Login,
|
|
92
64
|
payload: {
|
|
93
|
-
user:
|
|
65
|
+
user: A
|
|
94
66
|
}
|
|
95
|
-
}),
|
|
67
|
+
}), r((/* @__PURE__ */ new Date()).getTime() + "");
|
|
96
68
|
});
|
|
97
|
-
},
|
|
98
|
-
|
|
69
|
+
}, [t, r, d]), u = l(async (e) => {
|
|
70
|
+
e && await t({
|
|
99
71
|
endPoint: "auth/logout",
|
|
100
72
|
method: "POST"
|
|
101
|
-
}),
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
}, []), /* @__PURE__ */
|
|
108
|
-
|
|
73
|
+
}), s({ type: n.Logout }), r((/* @__PURE__ */ new Date()).getTime() + "");
|
|
74
|
+
}, [t, r]), S = l(() => {
|
|
75
|
+
u(!1);
|
|
76
|
+
}, [u]);
|
|
77
|
+
return f(function() {
|
|
78
|
+
o || T(w.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, S);
|
|
79
|
+
}, [o]), /* @__PURE__ */ C(
|
|
80
|
+
z.Provider,
|
|
109
81
|
{
|
|
110
82
|
value: {
|
|
111
|
-
...
|
|
112
|
-
login:
|
|
113
|
-
logout:
|
|
83
|
+
...E,
|
|
84
|
+
login: D,
|
|
85
|
+
logout: u
|
|
114
86
|
},
|
|
115
|
-
children:
|
|
87
|
+
children: h
|
|
116
88
|
}
|
|
117
89
|
);
|
|
118
90
|
}
|
|
119
91
|
export {
|
|
120
|
-
|
|
121
|
-
|
|
92
|
+
z as A,
|
|
93
|
+
b as a
|
|
122
94
|
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
var
|
|
1
|
+
var t = /* @__PURE__ */ ((i) => (i.Initial = "INITIALIZE", i.Login = "LOGIN", i.Logout = "LOGOUT", i))(t || {});
|
|
2
|
+
const a = {
|
|
3
|
+
isAuthenticated: !1,
|
|
4
|
+
isInitialized: !1,
|
|
5
|
+
user: null
|
|
6
|
+
};
|
|
2
7
|
export {
|
|
3
|
-
|
|
8
|
+
t as E,
|
|
9
|
+
a as i
|
|
4
10
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const r = (u, e) => {
|
|
2
|
+
switch (e.type) {
|
|
3
|
+
case "INITIALIZE":
|
|
4
|
+
return {
|
|
5
|
+
isAuthenticated: e.payload.isAuthenticated,
|
|
6
|
+
isInitialized: !0,
|
|
7
|
+
user: e.payload.user
|
|
8
|
+
};
|
|
9
|
+
case "LOGIN":
|
|
10
|
+
return {
|
|
11
|
+
...u,
|
|
12
|
+
isAuthenticated: !0,
|
|
13
|
+
user: e.payload.user
|
|
14
|
+
};
|
|
15
|
+
case "LOGOUT":
|
|
16
|
+
return {
|
|
17
|
+
...u,
|
|
18
|
+
isAuthenticated: !1,
|
|
19
|
+
user: null
|
|
20
|
+
};
|
|
21
|
+
default:
|
|
22
|
+
return u;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
r as J
|
|
27
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './AuthContext';
|
|
2
|
-
export type { UserAuth, AuthState } from './types';
|
|
2
|
+
export type { UserAuth, AuthState, AuthUserType } from './types';
|
|
@@ -21,6 +21,18 @@ export interface UserAuth {
|
|
|
21
21
|
}
|
|
22
22
|
export type AuthUserType = Maybe<UserAuth>;
|
|
23
23
|
export type AuthProviderProps = {
|
|
24
|
+
/**
|
|
25
|
+
* isMicroFrontEnd: indica si la aplicación es un microfrontend
|
|
26
|
+
* default: false
|
|
27
|
+
*/
|
|
28
|
+
isMicroFrontEnd?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* loggedUser: usuario de la aplicación, solo aplica para Microfrontends, porque se pasa la información del usuario directamente desde el host
|
|
31
|
+
*/
|
|
32
|
+
loggedUser?: AuthUserType;
|
|
33
|
+
/**
|
|
34
|
+
* children: hijos del componente
|
|
35
|
+
*/
|
|
24
36
|
children: ReactNode;
|
|
25
37
|
};
|
|
26
38
|
export type ActionMap<M extends {
|