datacenter-lib-react-ts 1.0.4 → 1.0.7
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/dist/cjs/auth/authCheck.js +8 -10
- package/dist/cjs/auth/authCheck.js.map +1 -1
- package/dist/cjs/auth/authRequired.js +10 -3
- package/dist/cjs/auth/authRequired.js.map +1 -1
- package/dist/cjs/auth/authentication.slice.js +21 -1
- package/dist/cjs/auth/authentication.slice.js.map +1 -1
- package/dist/cjs/auth/userDropdownMenu.js +40 -0
- package/dist/cjs/auth/userDropdownMenu.js.map +1 -0
- package/dist/cjs/auth/userOptions.js +14 -18
- package/dist/cjs/auth/userOptions.js.map +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/auth/authCheck.js +9 -11
- package/dist/esm/auth/authCheck.js.map +1 -1
- package/dist/esm/auth/authRequired.js +10 -3
- package/dist/esm/auth/authRequired.js.map +1 -1
- package/dist/esm/auth/authentication.slice.js +18 -0
- package/dist/esm/auth/authentication.slice.js.map +1 -1
- package/dist/esm/auth/userDropdownMenu.js +35 -0
- package/dist/esm/auth/userDropdownMenu.js.map +1 -0
- package/dist/esm/auth/userOptions.js +15 -19
- package/dist/esm/auth/userOptions.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/types/auth/authentication.slice.d.ts +10 -5
- package/dist/types/auth/userDropdownMenu.d.ts +13 -0
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/auth/authCheck.tsx +9 -13
- package/src/auth/authRequired.tsx +12 -5
- package/src/auth/authentication.slice.tsx +31 -6
- package/src/auth/userDropdownMenu.tsx +78 -0
- package/src/auth/userOptions.tsx +19 -29
- package/src/index.tsx +2 -2
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthCheckComponent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const datacenter_lib_common_ts_1 = require("datacenter-lib-common-ts");
|
|
5
6
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
7
|
+
const react_redux_1 = require("react-redux");
|
|
6
8
|
const react_router_dom_1 = require("react-router-dom");
|
|
7
9
|
const authentication_slice_1 = require("./authentication.slice");
|
|
8
10
|
const authUtils_1 = require("./authUtils");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const datacenter_lib_common_ts_1 = require("datacenter-lib-common-ts");
|
|
12
|
-
const AuthCheckComponent = ({ authenticationState, /*authUrlBase, redirectUrl,*/ baseApiUrl, children }) => {
|
|
13
|
-
const navigate = (0, react_router_dom_2.useNavigate)();
|
|
11
|
+
const AuthCheckComponent = ({ authenticationState, baseApiUrl, children }) => {
|
|
12
|
+
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
14
13
|
const location = (0, react_router_dom_1.useLocation)();
|
|
15
14
|
const dispatch = (0, react_redux_1.useDispatch)();
|
|
16
15
|
const queryParams = new URLSearchParams(location.search);
|
|
@@ -22,7 +21,7 @@ const AuthCheckComponent = ({ authenticationState, /*authUrlBase, redirectUrl,*/
|
|
|
22
21
|
navigate(newPath, { replace: true });
|
|
23
22
|
};
|
|
24
23
|
(0, react_1.useEffect)(() => {
|
|
25
|
-
if (!authenticationState.
|
|
24
|
+
if (!new authentication_slice_1.AuthenticationStateHelper({ state: authenticationState }).authenticated && !authenticationState.options?.loading) {
|
|
26
25
|
if (authUuid) {
|
|
27
26
|
dispatch((0, authentication_slice_1.authenticationStateLoadFromApi)({
|
|
28
27
|
baseApiUrl,
|
|
@@ -35,15 +34,14 @@ const AuthCheckComponent = ({ authenticationState, /*authUrlBase, redirectUrl,*/
|
|
|
35
34
|
}));
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
else if (authenticationState.
|
|
39
|
-
// caso o usuario ja tenha logado e
|
|
37
|
+
else if (new authentication_slice_1.AuthenticationStateHelper({ state: authenticationState }).authenticated && authUuid) {
|
|
38
|
+
// caso o usuario ja tenha logado e tenta acessar a pagina de autenticacao, o redirect manda o authUuid
|
|
40
39
|
// nesse cenario, deve-se eliminar o authUuid da url
|
|
41
40
|
// isso vale para autenticacao em um dominio diferente do dominio do autenticador
|
|
42
41
|
// para recursos no mesmo dominio do autenticador, o redirect quando o usuario já tem autenticado esta correto, ou seja,
|
|
43
|
-
// ele nao manda o authUuid caso o usuario já esteja logado, em
|
|
42
|
+
// ele nao manda o authUuid caso o usuario já esteja logado, em dominios diferentes nao tem como o autenticador saber se o app esta logado
|
|
44
43
|
onGetAuthFinish();
|
|
45
44
|
}
|
|
46
|
-
// }, [authenticationState, location]);
|
|
47
45
|
}, [authenticationState]);
|
|
48
46
|
return react_1.default.createElement(react_1.default.Fragment, null, children);
|
|
49
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authCheck.js","sourceRoot":"","sources":["../../../src/auth/authCheck.tsx"],"names":[],"mappings":";;;;AACA,uDAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"authCheck.js","sourceRoot":"","sources":["../../../src/auth/authCheck.tsx"],"names":[],"mappings":";;;;AACA,uEAAkG;AAClG,uDAAoD;AACpD,6CAA0C;AAC1C,uDAA4D;AAC5D,iEAAyH;AACzH,2CAAwC;AAQjC,MAAM,kBAAkB,GAAuC,CAAC,EAAE,mBAAmB,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtH,MAAM,QAAQ,GAAG,IAAA,8BAAW,GAAE,CAAA;IAC9B,MAAM,QAAQ,GAAG,IAAA,8BAAW,GAAE,CAAA;IAC9B,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAO,CAAA;IACnC,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,qBAAS,CAAC,uBAAuB,CAAC,CAAA;IAEnE,MAAM,e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
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
6
|
const react_router_dom_1 = require("react-router-dom");
|
|
7
|
+
const authentication_slice_1 = require("./authentication.slice");
|
|
7
8
|
const authUtils_1 = require("./authUtils");
|
|
8
|
-
const AuthRequiredComponent = ({ authenticationState, authUrlBase, redirectUrl,
|
|
9
|
+
const AuthRequiredComponent = ({ authenticationState, authUrlBase, redirectUrl, children }) => {
|
|
9
10
|
const location = (0, react_router_dom_1.useLocation)();
|
|
10
11
|
const queryParams = new URLSearchParams(location.search);
|
|
11
12
|
const authUuid = queryParams.get(authUtils_1.AuthUtils.authUuidQueryStringName);
|
|
12
13
|
(0, react_1.useEffect)(() => {
|
|
13
|
-
if (!authenticationState.
|
|
14
|
+
if (!new authentication_slice_1.AuthenticationStateHelper({ state: authenticationState, }).authenticated && !authenticationState.options?.loading) {
|
|
14
15
|
if (!authUuid) {
|
|
15
16
|
if (!authUrlBase.includes('/login'))
|
|
16
17
|
authUrlBase = `${authUrlBase}/login`;
|
|
18
|
+
localStorage.clear();
|
|
19
|
+
sessionStorage.clear();
|
|
20
|
+
document.cookie.split(";").forEach(cookie => {
|
|
21
|
+
const name = cookie.split("=")[0].trim();
|
|
22
|
+
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
23
|
+
});
|
|
17
24
|
window.location.href = `${authUrlBase}?${authUtils_1.AuthUtils.authToRedirectQueryStringName}=${encodeURIComponent(redirectUrl)}`;
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
27
|
}, [authenticationState]);
|
|
21
|
-
if (!authenticationState.
|
|
28
|
+
if (!new authentication_slice_1.AuthenticationStateHelper({ state: authenticationState, }).authenticated) {
|
|
22
29
|
return null;
|
|
23
30
|
}
|
|
24
31
|
return react_1.default.createElement(react_1.default.Fragment, null, children);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authRequired.js","sourceRoot":"","sources":["../../../src/auth/authRequired.tsx"],"names":[],"mappings":";;;;AACA,uDAAoD;AACpD,uDAA+C;
|
|
1
|
+
{"version":3,"file":"authRequired.js","sourceRoot":"","sources":["../../../src/auth/authRequired.tsx"],"names":[],"mappings":";;;;AACA,uDAAoD;AACpD,uDAA+C;AAC/C,iEAAyF;AACzF,2CAAwC;AASjC,MAAM,qBAAqB,GAA0C,CAAC,EAAE,mBAAmB,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC1I,MAAM,QAAQ,GAAG,IAAA,8BAAW,GAAE,CAAA;IAC9B,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,qBAAS,CAAC,uBAAuB,CAAC,CAAA;IAEnE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,IAAI,gDAAyB,CAAC,EAAE,KAAK,EAAE,mBAAmB,GAAG,CAAC,CAAC,aAAa,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;YAC3H,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC;oBACjC,WAAW,GAAG,GAAG,WAAW,QAAQ,CAAA;gBAEtC,YAAY,CAAC,KAAK,EAAE,CAAA;gBACpB,cAAc,CAAC,KAAK,EAAE,CAAA;gBACtB,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;oBAC1C,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;oBACzC,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,mDAAmD,CAAC;gBAC/E,CAAC,CAAC,CAAC;gBAEH,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,WAAW,IAAI,qBAAS,CAAC,6BAA6B,IAAI,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAA;YACvH,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAE1B,IAAI,CAAC,IAAI,gDAAyB,CAAC,EAAE,KAAK,EAAE,mBAAmB,GAAG,CAAC,CAAC,aAAa,EAAE,CAAC;QAClF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,8DAAG,QAAQ,CAAI,CAAA;AACxB,CAAC,CAAC;AA5BW,QAAA,qBAAqB,yBA4BhC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.authenticationStateSet = exports.authenticationStateLogout = exports.authenticationSlice = exports.authenticationStateLoadFromApi = void 0;
|
|
4
|
+
exports.AuthenticationStateHelper = exports.authenticationStateSet = exports.authenticationStateLogout = exports.authenticationSlice = exports.authenticationStateLoadFromApi = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
5
6
|
const toolkit_1 = require("@reduxjs/toolkit");
|
|
6
7
|
const datacenter_lib_common_ts_1 = require("datacenter-lib-common-ts");
|
|
7
8
|
const fwork_jsts_common_1 = require("fwork-jsts-common");
|
|
8
9
|
const jwt_decode_1 = require("jwt-decode"); // dont use jsonwebtokens package here, its only for node projects
|
|
10
|
+
const moment_1 = tslib_1.__importDefault(require("moment"));
|
|
9
11
|
const cookie = fwork_jsts_common_1.WebUtils.getCookie('@authenticationState');
|
|
10
12
|
const cookieObj = cookie ? JSON.parse(cookie) : null;
|
|
11
13
|
const initState = cookieObj || {};
|
|
@@ -69,4 +71,22 @@ exports.authenticationSlice = (0, toolkit_1.createSlice)({
|
|
|
69
71
|
});
|
|
70
72
|
_a = exports.authenticationSlice.actions, exports.authenticationStateLogout = _a.logout, exports.authenticationStateSet = _a.set;
|
|
71
73
|
exports.default = exports.authenticationSlice.reducer;
|
|
74
|
+
class AuthenticationStateHelper {
|
|
75
|
+
constructor(args) {
|
|
76
|
+
this.state = args.state;
|
|
77
|
+
}
|
|
78
|
+
get authenticated() {
|
|
79
|
+
let result = false;
|
|
80
|
+
if (this.state.payload?.token)
|
|
81
|
+
try {
|
|
82
|
+
var decToken = (0, jwt_decode_1.jwtDecode)(this.state.payload?.token);
|
|
83
|
+
result = (decToken.exp || 0) >= (0, moment_1.default)().unix();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
result = false;
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.AuthenticationStateHelper = AuthenticationStateHelper;
|
|
72
92
|
//# sourceMappingURL=authentication.slice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.slice.js","sourceRoot":"","sources":["../../../src/auth/authentication.slice.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authentication.slice.js","sourceRoot":"","sources":["../../../src/auth/authentication.slice.tsx"],"names":[],"mappings":";;;;;AAAA,8CAAgF;AAChF,uEAAwO;AACxO,yDAA6C;AAC7C,2CAAuC,CAAC,kEAAkE;AAC1G,4DAA4B;AAa5B,MAAM,MAAM,GAAG,4BAAQ,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAA;AACzD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAEpD,MAAM,SAAS,GAAyB,SAAS,IAAI,EAAE,CAAA;AAE1C,QAAA,8BAA8B,GAAG,IAAA,0BAAgB,EAC5D,gCAAgC,EAChC,KAAK,EAAE,GAON,EAAE,EAAE;IACH,IAAI,CAAC;QACH,IAAI,MAAM,GAAyB,EAAE,CAAA;QAErC,MAAM,QAAQ,GAAG,MAAM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AC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;IACzB,CAAC;IAED,IAAI,aAAa;QACf,IAAI,MAAM,GAAG,KAAK,CAAA;QAElB,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK;YAC3B,IAAI,CAAC;gBACH,IAAI,QAAQ,GAA6B,IAAA,sBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;gBAC7E,MAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,IAAA,gBAAM,GAAE,CAAC,IAAI,EAAE,CAAA;YACjD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,GAAG,KAAK,CAAA;YAChB,CAAC;QAEH,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAtBD,8DAsBC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserDropdownMenu = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
7
|
+
const md_1 = require("react-icons/md");
|
|
8
|
+
const UserDropdownMenu = ({ user, anchorEl, open, onClose, onLogOut, onProfile, }) => {
|
|
9
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
10
|
+
react_1.default.createElement(material_1.Menu, { anchorEl: anchorEl, open: open, onClose: onClose, anchorOrigin: { vertical: "bottom", horizontal: "right" }, transformOrigin: { vertical: "top", horizontal: "right" }, PaperProps: {
|
|
11
|
+
sx: {
|
|
12
|
+
marginTop: .5,
|
|
13
|
+
minWidth: 260,
|
|
14
|
+
borderRadius: 2,
|
|
15
|
+
boxShadow: "0 8px 24px rgba(0,0,0,0.12)",
|
|
16
|
+
overflow: "hidden",
|
|
17
|
+
},
|
|
18
|
+
}, MenuListProps: { sx: { p: 0 } } },
|
|
19
|
+
react_1.default.createElement(material_1.MenuItem, { onClick: onProfile, sx: {
|
|
20
|
+
gap: 1,
|
|
21
|
+
p: 2,
|
|
22
|
+
// py: 1.2,
|
|
23
|
+
fontWeight: 500,
|
|
24
|
+
} },
|
|
25
|
+
react_1.default.createElement(material_1.ListItemText, { primary: user.name, secondary: user.email })),
|
|
26
|
+
react_1.default.createElement(material_1.Divider, { style: { margin: 0 } }),
|
|
27
|
+
react_1.default.createElement(material_1.MenuItem, { onClick: onLogOut, sx: {
|
|
28
|
+
gap: 1,
|
|
29
|
+
py: 1.2,
|
|
30
|
+
fontWeight: 500,
|
|
31
|
+
color: "error.main",
|
|
32
|
+
"&:hover": {
|
|
33
|
+
backgroundColor: "rgba(211, 47, 47, 0.08)",
|
|
34
|
+
},
|
|
35
|
+
} },
|
|
36
|
+
react_1.default.createElement(md_1.MdLogout, { size: 20 }),
|
|
37
|
+
"Sair"))));
|
|
38
|
+
};
|
|
39
|
+
exports.UserDropdownMenu = UserDropdownMenu;
|
|
40
|
+
//# sourceMappingURL=userDropdownMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userDropdownMenu.js","sourceRoot":"","sources":["../../../src/auth/userDropdownMenu.tsx"],"names":[],"mappings":";;;;AAAA,4CAA4F;AAE5F,0DAAyB;AACzB,uCAAyC;AAWlC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,SAAS,GACH,EAAE,EAAE;IACV,OAAO,CACL;QACE,8BAAC,eAAI,IACH,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,EACzD,eAAe,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,EACzD,UAAU,EAAE;gBACV,EAAE,EAAE;oBACF,SAAS,EAAE,EAAE;oBACb,QAAQ,EAAE,GAAG;oBACb,YAAY,EAAE,CAAC;oBACf,SAAS,EAAE,6BAA6B;oBACxC,QAAQ,EAAE,QAAQ;iBACnB;aACF,EACD,aAAa,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;YAE/B,8BAAC,mBAAQ,IACP,OAAO,EAAE,SAAS,EAClB,EAAE,EAAE;oBACF,GAAG,EAAE,CAAC;oBACN,CAAC,EAAE,CAAC;oBACJ,WAAW;oBACX,UAAU,EAAE,GAAG;iBAChB;gBAED,8BAAC,uBAAY,IACX,OAAO,EAAE,IAAI,CAAC,IAAI,EAClB,SAAS,EAAE,IAAI,CAAC,KAAK,GACrB,CACO;YAEX,8BAAC,kBAAO,IAAC,KAAK,EAAE,EAAC,MAAM,EAAE,CAAC,EAAC,GAAG;YAG9B,8BAAC,mBAAQ,IACP,OAAO,EAAE,QAAQ,EACjB,EAAE,EAAE;oBACF,GAAG,EAAE,CAAC;oBACN,EAAE,EAAE,GAAG;oBACP,UAAU,EAAE,GAAG;oBACf,KAAK,EAAE,YAAY;oBACnB,SAAS,EAAE;wBACT,eAAe,EAAE,yBAAyB;qBAC3C;iBACF;gBAED,8BAAC,aAAQ,IAAC,IAAI,EAAE,EAAE,GAAI;uBAEb,CACN,CACN,CACJ,CAAA;AACH,CAAC,CAAA;AA/DY,QAAA,gBAAgB,oBA+D5B"}
|
|
@@ -2,34 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserOptionsComponent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const Person_1 = tslib_1.__importDefault(require("@mui/icons-material/Person"));
|
|
6
6
|
const material_1 = require("@mui/material");
|
|
7
7
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
8
8
|
const react_redux_1 = require("react-redux");
|
|
9
9
|
const authentication_slice_1 = require("./authentication.slice");
|
|
10
|
+
const userDropdownMenu_1 = require("./userDropdownMenu");
|
|
10
11
|
const UserOptionsComponent = ({ user, datacenterAuthBaseUrl, onLogOut }) => {
|
|
11
12
|
const dispatch = (0, react_redux_1.useDispatch)();
|
|
12
13
|
const [menuAnchor, setAnchorElemnt] = (0, react_1.useState)(null);
|
|
13
14
|
const openMenu = Boolean(menuAnchor);
|
|
14
15
|
return react_1.default.createElement(react_1.default.Fragment, null,
|
|
15
|
-
react_1.default.createElement(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (onLogOut)
|
|
26
|
-
onLogOut();
|
|
27
|
-
setAnchorElemnt(null);
|
|
28
|
-
} },
|
|
29
|
-
react_1.default.createElement(Logout_1.default, null),
|
|
30
|
-
" Sair")),
|
|
16
|
+
react_1.default.createElement(userDropdownMenu_1.UserDropdownMenu, { user: user, anchorEl: menuAnchor, open: openMenu, onClose: () => setAnchorElemnt(null), onLogOut: () => {
|
|
17
|
+
dispatch((0, authentication_slice_1.authenticationStateLogout)());
|
|
18
|
+
if (onLogOut)
|
|
19
|
+
onLogOut();
|
|
20
|
+
setAnchorElemnt(null);
|
|
21
|
+
}, onProfile: () => {
|
|
22
|
+
let authUrl = `${datacenterAuthBaseUrl}/profile`;
|
|
23
|
+
window.open(authUrl, '_blank')?.focus();
|
|
24
|
+
setAnchorElemnt(null);
|
|
25
|
+
} }),
|
|
31
26
|
react_1.default.createElement(material_1.IconButton, { onClick: e => setAnchorElemnt(e.currentTarget) },
|
|
32
|
-
react_1.default.createElement(material_1.Avatar, { src: user.imageUrl }
|
|
27
|
+
react_1.default.createElement(material_1.Avatar, { src: user.imageUrl },
|
|
28
|
+
react_1.default.createElement(Person_1.default, null))));
|
|
33
29
|
};
|
|
34
30
|
exports.UserOptionsComponent = UserOptionsComponent;
|
|
35
31
|
//# sourceMappingURL=userOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userOptions.js","sourceRoot":"","sources":["../../../src/auth/userOptions.tsx"],"names":[],"mappings":";;;;AAAA,gFAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"userOptions.js","sourceRoot":"","sources":["../../../src/auth/userOptions.tsx"],"names":[],"mappings":";;;;AAAA,gFAAmD;AACnD,4CAAkD;AAElD,uDAAuC;AACvC,6CAAyC;AACzC,iEAAkE;AAClE,yDAAqD;AAQ9C,MAAM,oBAAoB,GAAyC,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtH,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAO,CAAA;IACnC,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAA+C,IAAI,CAAC,CAAA;IAClG,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAEpC,OAAO;QACL,8BAAC,mCAAgB,IACf,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,UAAU,EACpB,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,EACpC,QAAQ,EAAE,GAAG,EAAE;gBACb,QAAQ,CAAC,IAAA,gDAAyB,GAAE,CAAC,CAAA;gBACrC,IAAI,QAAQ;oBAAE,QAAQ,EAAE,CAAA;gBACxB,eAAe,CAAC,IAAI,CAAC,CAAA;YACvB,CAAC,EACD,SAAS,EAAE,GAAG,EAAE;gBACd,IAAI,OAAO,GAAG,GAAG,qBAAqB,UAAU,CAAA;gBAChD,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAA;gBACvC,eAAe,CAAC,IAAI,CAAC,CAAA;YACvB,CAAC,GACD;QAEF,8BAAC,qBAAU,IACT,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC;YAC/C,8BAAC,iBAAM,IAAC,GAAG,EAAE,IAAI,CAAC,QAAQ;gBACvB,8BAAC,gBAAU,OAAG,CACP,CAAa,CACvB,CAAA;AACL,CAAC,CAAA;AA7BY,QAAA,oBAAoB,wBA6BhC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserOptionsComponent = exports.AuthUtils = exports.AuthRequiredComponent = exports.authenticationStateSet = exports.authenticationSlice = exports.authenticationStateLogout = exports.authenticationStateLoadFromApi = exports.authenticationReducer = exports.AuthCheckComponent = void 0;
|
|
3
|
+
exports.UserOptionsComponent = exports.AuthUtils = exports.AuthRequiredComponent = exports.authenticationStateSet = exports.authenticationSlice = exports.authenticationStateLogout = exports.AuthenticationStateHelper = exports.authenticationStateLoadFromApi = exports.authenticationReducer = exports.AuthCheckComponent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const authCheck_1 = require("./auth/authCheck");
|
|
6
6
|
Object.defineProperty(exports, "AuthCheckComponent", { enumerable: true, get: function () { return authCheck_1.AuthCheckComponent; } });
|
|
7
7
|
const authentication_slice_1 = tslib_1.__importStar(require("./auth/authentication.slice"));
|
|
8
8
|
exports.authenticationReducer = authentication_slice_1.default;
|
|
9
9
|
Object.defineProperty(exports, "authenticationStateLoadFromApi", { enumerable: true, get: function () { return authentication_slice_1.authenticationStateLoadFromApi; } });
|
|
10
|
+
Object.defineProperty(exports, "AuthenticationStateHelper", { enumerable: true, get: function () { return authentication_slice_1.AuthenticationStateHelper; } });
|
|
10
11
|
Object.defineProperty(exports, "authenticationStateLogout", { enumerable: true, get: function () { return authentication_slice_1.authenticationStateLogout; } });
|
|
11
12
|
Object.defineProperty(exports, "authenticationSlice", { enumerable: true, get: function () { return authentication_slice_1.authenticationSlice; } });
|
|
12
13
|
Object.defineProperty(exports, "authenticationStateSet", { enumerable: true, get: function () { return authentication_slice_1.authenticationStateSet; } });
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";;;;AAAA,gDAAgF;AAO9E,mGAPO,8BAAkB,OAOP;AANpB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";;;;AAAA,gDAAgF;AAO9E,mGAPO,8BAAkB,OAOP;AANpB,4FAAiP;AAO/O,gCAPK,8BAAqB,CAOL;AAAE,+GAPO,qDAA8B,OAOP;AAAE,0GAPO,gDAAyB,OAOP;AAA4C,0GAPO,gDAAyB,OAOP;AAAE,oGAPO,0CAAmB,OAOP;AAAE,uGAPO,6CAAsB,OAOP;AANpM,sDAAyF;AAOvF,sGAPO,oCAAqB,OAOP;AANvB,gDAA6C;AAO3C,0FAPO,qBAAS,OAOP;AANX,oDAAsF;AAOpF,qGAPO,kCAAoB,OAOP"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { AuthenticationType } from "datacenter-lib-common-ts";
|
|
1
2
|
import React, { useEffect } from "react";
|
|
2
|
-
import { useLocation } from "react-router-dom";
|
|
3
|
-
import { authenticationStateLoadFromApi } from "./authentication.slice";
|
|
4
|
-
import { AuthUtils } from "./authUtils";
|
|
5
|
-
import { useNavigate } from 'react-router-dom';
|
|
6
3
|
import { useDispatch } from "react-redux";
|
|
7
|
-
import {
|
|
8
|
-
|
|
4
|
+
import { useLocation, useNavigate } from "react-router-dom";
|
|
5
|
+
import { AuthenticationStateHelper, authenticationStateLoadFromApi } from "./authentication.slice";
|
|
6
|
+
import { AuthUtils } from "./authUtils";
|
|
7
|
+
export const AuthCheckComponent = ({ authenticationState, baseApiUrl, children }) => {
|
|
9
8
|
const navigate = useNavigate();
|
|
10
9
|
const location = useLocation();
|
|
11
10
|
const dispatch = useDispatch();
|
|
@@ -18,7 +17,7 @@ export const AuthCheckComponent = ({ authenticationState, /*authUrlBase, redirec
|
|
|
18
17
|
navigate(newPath, { replace: true });
|
|
19
18
|
};
|
|
20
19
|
useEffect(() => {
|
|
21
|
-
if (!authenticationState.
|
|
20
|
+
if (!new AuthenticationStateHelper({ state: authenticationState }).authenticated && !authenticationState.options?.loading) {
|
|
22
21
|
if (authUuid) {
|
|
23
22
|
dispatch(authenticationStateLoadFromApi({
|
|
24
23
|
baseApiUrl,
|
|
@@ -31,15 +30,14 @@ export const AuthCheckComponent = ({ authenticationState, /*authUrlBase, redirec
|
|
|
31
30
|
}));
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
|
-
else if (authenticationState.
|
|
35
|
-
// caso o usuario ja tenha logado e
|
|
33
|
+
else if (new AuthenticationStateHelper({ state: authenticationState }).authenticated && authUuid) {
|
|
34
|
+
// caso o usuario ja tenha logado e tenta acessar a pagina de autenticacao, o redirect manda o authUuid
|
|
36
35
|
// nesse cenario, deve-se eliminar o authUuid da url
|
|
37
36
|
// isso vale para autenticacao em um dominio diferente do dominio do autenticador
|
|
38
37
|
// para recursos no mesmo dominio do autenticador, o redirect quando o usuario já tem autenticado esta correto, ou seja,
|
|
39
|
-
// ele nao manda o authUuid caso o usuario já esteja logado, em
|
|
38
|
+
// ele nao manda o authUuid caso o usuario já esteja logado, em dominios diferentes nao tem como o autenticador saber se o app esta logado
|
|
40
39
|
onGetAuthFinish();
|
|
41
40
|
}
|
|
42
|
-
// }, [authenticationState, location]);
|
|
43
41
|
}, [authenticationState]);
|
|
44
42
|
return React.createElement(React.Fragment, null, children);
|
|
45
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authCheck.js","sourceRoot":"","sources":["../../../src/auth/authCheck.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"authCheck.js","sourceRoot":"","sources":["../../../src/auth/authCheck.tsx"],"names":[],"mappings":"AACA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IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;YAC1H,IAAI,QAAQ,EAAE,CAAC;gBACb,QAAQ,CAAC,8BAA8B,CAAC;oBACtC,UAAU;oBACV,cAAc,EAAE;wBACd,IAAI,EAAE,kBAAkB,CAAC,IAAI;wBAC7B,IAAI,EAAE,QAAQ;qBACuB;oBACvC,SAAS,EAAE,eAAe;oBAC1B,OAAO,EAAE,eAAe;iBACzB,CAAC,CAAC,CAAA;YACL,CAAC;QACH,CAAC;aACI,IAAI,IAAI,yBAAyB,CAAC,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC,CAAC,aAAa,IAAI,QAAQ,EAAE,CAAC;YACjG,uGAAuG;YACvG,oDAAoD;YACpD,iFAAiF;YACjF,yHAAyH;YACzH,0IAA0I;YAC1I,eAAe,EAAE,CAAA;QACnB,CAAC;IACH,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAE1B,OAAO,0CAAG,QAAQ,CAAI,CAAA;AACxB,CAAC,CAAC"}
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import React, { useEffect } from "react";
|
|
2
2
|
import { useLocation } from "react-router-dom";
|
|
3
|
+
import { AuthenticationStateHelper } from "./authentication.slice";
|
|
3
4
|
import { AuthUtils } from "./authUtils";
|
|
4
|
-
export const AuthRequiredComponent = ({ authenticationState, authUrlBase, redirectUrl,
|
|
5
|
+
export const AuthRequiredComponent = ({ authenticationState, authUrlBase, redirectUrl, children }) => {
|
|
5
6
|
const location = useLocation();
|
|
6
7
|
const queryParams = new URLSearchParams(location.search);
|
|
7
8
|
const authUuid = queryParams.get(AuthUtils.authUuidQueryStringName);
|
|
8
9
|
useEffect(() => {
|
|
9
|
-
if (!authenticationState.
|
|
10
|
+
if (!new AuthenticationStateHelper({ state: authenticationState, }).authenticated && !authenticationState.options?.loading) {
|
|
10
11
|
if (!authUuid) {
|
|
11
12
|
if (!authUrlBase.includes('/login'))
|
|
12
13
|
authUrlBase = `${authUrlBase}/login`;
|
|
14
|
+
localStorage.clear();
|
|
15
|
+
sessionStorage.clear();
|
|
16
|
+
document.cookie.split(";").forEach(cookie => {
|
|
17
|
+
const name = cookie.split("=")[0].trim();
|
|
18
|
+
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
19
|
+
});
|
|
13
20
|
window.location.href = `${authUrlBase}?${AuthUtils.authToRedirectQueryStringName}=${encodeURIComponent(redirectUrl)}`;
|
|
14
21
|
}
|
|
15
22
|
}
|
|
16
23
|
}, [authenticationState]);
|
|
17
|
-
if (!authenticationState.
|
|
24
|
+
if (!new AuthenticationStateHelper({ state: authenticationState, }).authenticated) {
|
|
18
25
|
return null;
|
|
19
26
|
}
|
|
20
27
|
return React.createElement(React.Fragment, null, children);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authRequired.js","sourceRoot":"","sources":["../../../src/auth/authRequired.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAa,SAAS,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"authRequired.js","sourceRoot":"","sources":["../../../src/auth/authRequired.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAa,SAAS,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAwB,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AASxC,MAAM,CAAC,MAAM,qBAAqB,GAA0C,CAAC,EAAE,mBAAmB,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC1I,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC,M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
|
2
2
|
import { AuthenticationsApiClient } from 'datacenter-lib-common-ts';
|
|
3
3
|
import { WebUtils } from 'fwork-jsts-common';
|
|
4
4
|
import { jwtDecode } from 'jwt-decode'; // dont use jsonwebtokens package here, its only for node projects
|
|
5
|
+
import moment from 'moment';
|
|
5
6
|
const cookie = WebUtils.getCookie('@authenticationState');
|
|
6
7
|
const cookieObj = cookie ? JSON.parse(cookie) : null;
|
|
7
8
|
const initState = cookieObj || {};
|
|
@@ -65,4 +66,21 @@ export const authenticationSlice = createSlice({
|
|
|
65
66
|
});
|
|
66
67
|
export const { logout: authenticationStateLogout, set: authenticationStateSet } = authenticationSlice.actions;
|
|
67
68
|
export default authenticationSlice.reducer;
|
|
69
|
+
export class AuthenticationStateHelper {
|
|
70
|
+
constructor(args) {
|
|
71
|
+
this.state = args.state;
|
|
72
|
+
}
|
|
73
|
+
get authenticated() {
|
|
74
|
+
let result = false;
|
|
75
|
+
if (this.state.payload?.token)
|
|
76
|
+
try {
|
|
77
|
+
var decToken = jwtDecode(this.state.payload?.token);
|
|
78
|
+
result = (decToken.exp || 0) >= moment().unix();
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
result = false;
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
68
86
|
//# sourceMappingURL=authentication.slice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.slice.js","sourceRoot":"","sources":["../../../src/auth/authentication.slice.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"authentication.slice.js","sourceRoot":"","sources":["../../../src/auth/authentication.slice.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAiB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAsK,MAAM,0BAA0B,CAAC;AACxO,OAAO,EAAE,QAAQ,EAAE,MAA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AK,CAAC,OAAO;gBACf,QAAQ,CAAC,SAAS,CAAC,sBAAsB,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;QACxE,CAAC,CAAC,CAAA;QACF,OAAO,CAAC,OAAO,CAAC,8BAA8B,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YACjE,IAAI,KAAK,CAAC,OAAO;gBACf,KAAK,CAAC,OAAO,CAAC,OAAO,GAAG,KAAK,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,yBAAyB,EAAE,GAAG,EAAE,sBAAsB,EAAE,GAAG,mBAAmB,CAAC,OAAO,CAAA;AAE7G,eAAe,mBAAmB,CAAC,OAAO,CAAA;AAE1C,MAAM,OAAO,yBAAyB;IAGpC,YAAY,IAEX;QACC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;IACzB,CAAC;IAED,IAAI,aAAa;QACf,IAAI,MAAM,GAAG,KAAK,CAAA;QAElB,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK;YAC3B,IAAI,CAAC;gBACH,IAAI,QAAQ,GAA6B,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;gBAC7E,MAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,IAAI,EAAE,CAAA;YACjD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,GAAG,KAAK,CAAA;YAChB,CAAC;QAEH,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Divider, ListItemText, Menu, MenuItem } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { MdLogout } from "react-icons/md";
|
|
4
|
+
export const UserDropdownMenu = ({ user, anchorEl, open, onClose, onLogOut, onProfile, }) => {
|
|
5
|
+
return (React.createElement(React.Fragment, null,
|
|
6
|
+
React.createElement(Menu, { anchorEl: anchorEl, open: open, onClose: onClose, anchorOrigin: { vertical: "bottom", horizontal: "right" }, transformOrigin: { vertical: "top", horizontal: "right" }, PaperProps: {
|
|
7
|
+
sx: {
|
|
8
|
+
marginTop: .5,
|
|
9
|
+
minWidth: 260,
|
|
10
|
+
borderRadius: 2,
|
|
11
|
+
boxShadow: "0 8px 24px rgba(0,0,0,0.12)",
|
|
12
|
+
overflow: "hidden",
|
|
13
|
+
},
|
|
14
|
+
}, MenuListProps: { sx: { p: 0 } } },
|
|
15
|
+
React.createElement(MenuItem, { onClick: onProfile, sx: {
|
|
16
|
+
gap: 1,
|
|
17
|
+
p: 2,
|
|
18
|
+
// py: 1.2,
|
|
19
|
+
fontWeight: 500,
|
|
20
|
+
} },
|
|
21
|
+
React.createElement(ListItemText, { primary: user.name, secondary: user.email })),
|
|
22
|
+
React.createElement(Divider, { style: { margin: 0 } }),
|
|
23
|
+
React.createElement(MenuItem, { onClick: onLogOut, sx: {
|
|
24
|
+
gap: 1,
|
|
25
|
+
py: 1.2,
|
|
26
|
+
fontWeight: 500,
|
|
27
|
+
color: "error.main",
|
|
28
|
+
"&:hover": {
|
|
29
|
+
backgroundColor: "rgba(211, 47, 47, 0.08)",
|
|
30
|
+
},
|
|
31
|
+
} },
|
|
32
|
+
React.createElement(MdLogout, { size: 20 }),
|
|
33
|
+
"Sair"))));
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=userDropdownMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userDropdownMenu.js","sourceRoot":"","sources":["../../../src/auth/userDropdownMenu.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAyB,MAAM,eAAe,CAAA;AAE5F,OAAO,KAAK,MAAM,OAA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BAC3C;iBACF;gBAED,oBAAC,QAAQ,IAAC,IAAI,EAAE,EAAE,GAAI;uBAEb,CACN,CACN,CACJ,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Avatar, IconButton
|
|
1
|
+
import PersonIcon from "@mui/icons-material/Person";
|
|
2
|
+
import { Avatar, IconButton } from "@mui/material";
|
|
3
3
|
import React, { useState } from "react";
|
|
4
4
|
import { useDispatch } from 'react-redux';
|
|
5
5
|
import { authenticationStateLogout } from './authentication.slice';
|
|
6
|
+
import { UserDropdownMenu } from './userDropdownMenu';
|
|
6
7
|
export const UserOptionsComponent = ({ user, datacenterAuthBaseUrl, onLogOut }) => {
|
|
7
8
|
const dispatch = useDispatch();
|
|
8
9
|
const [menuAnchor, setAnchorElemnt] = useState(null);
|
|
9
10
|
const openMenu = Boolean(menuAnchor);
|
|
10
11
|
return React.createElement(React.Fragment, null,
|
|
11
|
-
React.createElement(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (onLogOut)
|
|
22
|
-
onLogOut();
|
|
23
|
-
setAnchorElemnt(null);
|
|
24
|
-
} },
|
|
25
|
-
React.createElement(LogoutIcon, null),
|
|
26
|
-
" Sair")),
|
|
12
|
+
React.createElement(UserDropdownMenu, { user: user, anchorEl: menuAnchor, open: openMenu, onClose: () => setAnchorElemnt(null), onLogOut: () => {
|
|
13
|
+
dispatch(authenticationStateLogout());
|
|
14
|
+
if (onLogOut)
|
|
15
|
+
onLogOut();
|
|
16
|
+
setAnchorElemnt(null);
|
|
17
|
+
}, onProfile: () => {
|
|
18
|
+
let authUrl = `${datacenterAuthBaseUrl}/profile`;
|
|
19
|
+
window.open(authUrl, '_blank')?.focus();
|
|
20
|
+
setAnchorElemnt(null);
|
|
21
|
+
} }),
|
|
27
22
|
React.createElement(IconButton, { onClick: e => setAnchorElemnt(e.currentTarget) },
|
|
28
|
-
React.createElement(Avatar, { src: user.imageUrl }
|
|
23
|
+
React.createElement(Avatar, { src: user.imageUrl },
|
|
24
|
+
React.createElement(PersonIcon, null))));
|
|
29
25
|
};
|
|
30
26
|
//# sourceMappingURL=userOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userOptions.js","sourceRoot":"","sources":["../../../src/auth/userOptions.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,4BAA4B,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"userOptions.js","sourceRoot":"","sources":["../../../src/auth/userOptions.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,4BAA4B,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAElD,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAQrD,MAAM,CAAC,MAAM,oBAAoB,GAAyC,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtH,MAAM,QAAQ,GAAG,WAAW,EAAO,CAAA;IACnC,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,GAAG,QAAQ,CAA+C,IAAI,CAAC,CAAA;IAClG,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAEpC,OAAO;QACL,oBAAC,gBAAgB,IACf,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,UAAU,EACpB,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,EACpC,QAAQ,EAAE,GAAG,EAAE;gBACb,QAAQ,CAAC,yBAAyB,EAAE,CAAC,CAAA;gBACrC,IAAI,QAAQ;oBAAE,QAAQ,EAAE,CAAA;gBACxB,eAAe,CAAC,IAAI,CAAC,CAAA;YACvB,CAAC,EACD,SAAS,EAAE,GAAG,EAAE;gBACd,IAAI,OAAO,GAAG,GAAG,qBAAqB,UAAU,CAAA;gBAChD,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAA;gBACvC,eAAe,CAAC,IAAI,CAAC,CAAA;YACvB,CAAC,GACD;QAEF,oBAAC,UAAU,IACT,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC;YAC/C,oBAAC,MAAM,IAAC,GAAG,EAAE,IAAI,CAAC,QAAQ;gBACvB,oBAAC,UAAU,OAAG,CACP,CAAa,CACvB,CAAA;AACL,CAAC,CAAA"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AuthCheckComponent, } from './auth/authCheck';
|
|
2
|
-
import authenticationReducer, { authenticationStateLoadFromApi, authenticationStateLogout, authenticationSlice, authenticationStateSet, } from './auth/authentication.slice';
|
|
2
|
+
import authenticationReducer, { authenticationStateLoadFromApi, AuthenticationStateHelper, authenticationStateLogout, authenticationSlice, authenticationStateSet, } from './auth/authentication.slice';
|
|
3
3
|
import { AuthRequiredComponent, } from './auth/authRequired';
|
|
4
4
|
import { AuthUtils, } from './auth/authUtils';
|
|
5
5
|
import { UserOptionsComponent, } from './auth/userOptions';
|
|
6
|
-
export { AuthCheckComponent, authenticationReducer, authenticationStateLoadFromApi, authenticationStateLogout, authenticationSlice, authenticationStateSet, AuthRequiredComponent, AuthUtils, UserOptionsComponent, };
|
|
6
|
+
export { AuthCheckComponent, authenticationReducer, authenticationStateLoadFromApi, AuthenticationStateHelper, authenticationStateLogout, authenticationSlice, authenticationStateSet, AuthRequiredComponent, AuthUtils, UserOptionsComponent, };
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,GAA6B,MAAM,kBAAkB,CAAA;AAChF,OAAO,qBAAqB,EAAE,EAAE,8BAA8B,EAA4C,yBAAyB,EAAE,mBAAmB,EAAE,sBAAsB,GAAG,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,GAA6B,MAAM,kBAAkB,CAAA;AAChF,OAAO,qBAAqB,EAAE,EAAE,8BAA8B,EAAE,yBAAyB,EAA4C,yBAAyB,EAAE,mBAAmB,EAAE,sBAAsB,GAAG,MAAM,6BAA6B,CAAA;AACjP,OAAO,EAAE,qBAAqB,GAAgC,MAAM,qBAAqB,CAAA;AACzF,OAAO,EAAE,SAAS,GAAG,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,oBAAoB,GAA+B,MAAM,oBAAoB,CAAA;AAEtF,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EAAE,8BAA8B,EAAE,yBAAyB,EAA4C,yBAAyB,EAAE,mBAAmB,EAAE,sBAAsB,EAClM,qBAAqB,EACrB,SAAS,EACT,oBAAoB,GACrB,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PayloadAction } from '@reduxjs/toolkit';
|
|
1
2
|
import { IAuthentication, IAuthenticationRequestBodyDefault, IAuthenticationRequestBodyFromGoogleToken, IAuthenticationRequestBodyFromUuid, IUser } from 'datacenter-lib-common-ts';
|
|
2
3
|
export interface IAuthenticationExt extends IAuthentication {
|
|
3
4
|
user: IUser;
|
|
@@ -24,12 +25,16 @@ export declare const authenticationStateLoadFromApi: import("@reduxjs/toolkit").
|
|
|
24
25
|
rejectedMeta?: unknown;
|
|
25
26
|
}>;
|
|
26
27
|
export declare const authenticationSlice: import("@reduxjs/toolkit").Slice<IAuthenticationState, {
|
|
27
|
-
set: (state: import("immer/dist/internal").WritableDraft<IAuthenticationState>, action:
|
|
28
|
-
payload: any;
|
|
29
|
-
type: string;
|
|
30
|
-
}) => void;
|
|
28
|
+
set: (state: import("immer/dist/internal").WritableDraft<IAuthenticationState>, action: PayloadAction<IAuthenticationState>) => void;
|
|
31
29
|
logout: (state: import("immer/dist/internal").WritableDraft<IAuthenticationState>) => void;
|
|
32
30
|
}, "authenticationSlice">;
|
|
33
|
-
export declare const authenticationStateLogout: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"authenticationSlice/logout">, authenticationStateSet: import("@reduxjs/toolkit").ActionCreatorWithPayload<
|
|
31
|
+
export declare const authenticationStateLogout: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"authenticationSlice/logout">, authenticationStateSet: import("@reduxjs/toolkit").ActionCreatorWithPayload<IAuthenticationState, "authenticationSlice/set">;
|
|
34
32
|
declare const _default: import("redux").Reducer<IAuthenticationState>;
|
|
35
33
|
export default _default;
|
|
34
|
+
export declare class AuthenticationStateHelper {
|
|
35
|
+
state: IAuthenticationState;
|
|
36
|
+
constructor(args: {
|
|
37
|
+
state: IAuthenticationState;
|
|
38
|
+
});
|
|
39
|
+
get authenticated(): boolean;
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PopoverVirtualElement } from "@mui/material";
|
|
2
|
+
import { IUser } from "datacenter-lib-common-ts";
|
|
3
|
+
import React from "react";
|
|
4
|
+
interface Props {
|
|
5
|
+
user: IUser;
|
|
6
|
+
anchorEl?: Element | PopoverVirtualElement | (() => Element) | (() => PopoverVirtualElement) | null | undefined;
|
|
7
|
+
open: boolean;
|
|
8
|
+
onClose?: () => void;
|
|
9
|
+
onLogOut?: () => void;
|
|
10
|
+
onProfile?: () => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const UserDropdownMenu: ({ user, anchorEl, open, onClose, onLogOut, onProfile, }: Props) => React.JSX.Element;
|
|
13
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthCheckComponent, IAuthCheckComponentProps } from './auth/authCheck';
|
|
2
|
-
import authenticationReducer, { authenticationStateLoadFromApi, IAuthenticationState, IAuthenticationExt, authenticationStateLogout, authenticationSlice, authenticationStateSet } from './auth/authentication.slice';
|
|
2
|
+
import authenticationReducer, { authenticationStateLoadFromApi, AuthenticationStateHelper, IAuthenticationState, IAuthenticationExt, authenticationStateLogout, authenticationSlice, authenticationStateSet } from './auth/authentication.slice';
|
|
3
3
|
import { AuthRequiredComponent, IAuthRequiredComponentProps } from './auth/authRequired';
|
|
4
4
|
import { AuthUtils } from './auth/authUtils';
|
|
5
5
|
import { UserOptionsComponent, IUserOptionsComponentProps } from './auth/userOptions';
|
|
6
|
-
export { AuthCheckComponent, IAuthCheckComponentProps, authenticationReducer, authenticationStateLoadFromApi,
|
|
6
|
+
export { AuthCheckComponent, IAuthCheckComponentProps, authenticationReducer, authenticationStateLoadFromApi, AuthenticationStateHelper, IAuthenticationExt, IAuthenticationState, authenticationStateLogout, authenticationSlice, authenticationStateSet, AuthRequiredComponent, IAuthRequiredComponentProps, AuthUtils, UserOptionsComponent, IUserOptionsComponentProps, };
|
package/package.json
CHANGED
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"release:minor": "standard-version -m && git add CHANGELOG.md && git commit -m \"updated CHANGELOG.md\" && npm version minor && git push origin && git push origin --tags && npm publish --access public",
|
|
62
62
|
"release:patch": "standard-version -p && git add CHANGELOG.md && git commit -m \"updated CHANGELOG.md\" && npm version patch && git push origin && git push origin --tags && npm publish --access public"
|
|
63
63
|
},
|
|
64
|
-
"version": "1.0.
|
|
64
|
+
"version": "1.0.7",
|
|
65
65
|
"exports": {
|
|
66
66
|
".": {
|
|
67
67
|
"require": "./dist/cjs/index.js",
|
package/src/auth/authCheck.tsx
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
|
|
2
|
+
import { AuthenticationType, IAuthenticationRequestBodyFromUuid } from "datacenter-lib-common-ts";
|
|
2
3
|
import React, { ReactNode, useEffect } from "react";
|
|
3
|
-
import { useLocation } from "react-router-dom";
|
|
4
|
-
import { authenticationStateLoadFromApi, IAuthenticationState } from "./authentication.slice";
|
|
5
|
-
import { AuthUtils } from "./authUtils";
|
|
6
|
-
import { useNavigate } from 'react-router-dom'
|
|
7
4
|
import { useDispatch } from "react-redux";
|
|
8
|
-
import {
|
|
5
|
+
import { useLocation, useNavigate } from "react-router-dom";
|
|
6
|
+
import { AuthenticationStateHelper, authenticationStateLoadFromApi, IAuthenticationState } from "./authentication.slice";
|
|
7
|
+
import { AuthUtils } from "./authUtils";
|
|
9
8
|
|
|
10
9
|
export interface IAuthCheckComponentProps {
|
|
11
10
|
authenticationState: IAuthenticationState,
|
|
12
11
|
baseApiUrl: string,
|
|
13
|
-
// authUrlBase: string,
|
|
14
|
-
// redirectUrl: string,
|
|
15
12
|
children: ReactNode;
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
export const AuthCheckComponent: React.FC<IAuthCheckComponentProps> = ({ authenticationState,
|
|
15
|
+
export const AuthCheckComponent: React.FC<IAuthCheckComponentProps> = ({ authenticationState, baseApiUrl, children }) => {
|
|
19
16
|
const navigate = useNavigate()
|
|
20
17
|
const location = useLocation()
|
|
21
18
|
const dispatch = useDispatch<any>()
|
|
@@ -30,7 +27,7 @@ export const AuthCheckComponent: React.FC<IAuthCheckComponentProps> = ({ authent
|
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
useEffect(() => {
|
|
33
|
-
if (!authenticationState.
|
|
30
|
+
if (!new AuthenticationStateHelper({ state: authenticationState }).authenticated && !authenticationState.options?.loading) {
|
|
34
31
|
if (authUuid) {
|
|
35
32
|
dispatch(authenticationStateLoadFromApi({
|
|
36
33
|
baseApiUrl,
|
|
@@ -43,15 +40,14 @@ export const AuthCheckComponent: React.FC<IAuthCheckComponentProps> = ({ authent
|
|
|
43
40
|
}))
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
|
-
else if (authenticationState.
|
|
47
|
-
// caso o usuario ja tenha logado e
|
|
43
|
+
else if (new AuthenticationStateHelper({ state: authenticationState }).authenticated && authUuid) {
|
|
44
|
+
// caso o usuario ja tenha logado e tenta acessar a pagina de autenticacao, o redirect manda o authUuid
|
|
48
45
|
// nesse cenario, deve-se eliminar o authUuid da url
|
|
49
46
|
// isso vale para autenticacao em um dominio diferente do dominio do autenticador
|
|
50
47
|
// para recursos no mesmo dominio do autenticador, o redirect quando o usuario já tem autenticado esta correto, ou seja,
|
|
51
|
-
// ele nao manda o authUuid caso o usuario já esteja logado, em
|
|
48
|
+
// ele nao manda o authUuid caso o usuario já esteja logado, em dominios diferentes nao tem como o autenticador saber se o app esta logado
|
|
52
49
|
onGetAuthFinish()
|
|
53
50
|
}
|
|
54
|
-
// }, [authenticationState, location]);
|
|
55
51
|
}, [authenticationState]);
|
|
56
52
|
|
|
57
53
|
return <>{children}</>
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
|
|
2
2
|
import React, { ReactNode, useEffect } from "react";
|
|
3
3
|
import { useLocation } from "react-router-dom";
|
|
4
|
-
import { IAuthenticationState } from "./authentication.slice";
|
|
4
|
+
import { AuthenticationStateHelper, IAuthenticationState } from "./authentication.slice";
|
|
5
5
|
import { AuthUtils } from "./authUtils";
|
|
6
6
|
|
|
7
7
|
export interface IAuthRequiredComponentProps {
|
|
8
8
|
authenticationState: IAuthenticationState,
|
|
9
|
-
// baseApiUrl: string,
|
|
10
9
|
authUrlBase: string,
|
|
11
10
|
redirectUrl: string,
|
|
12
11
|
children: ReactNode;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
export const AuthRequiredComponent: React.FC<IAuthRequiredComponentProps> = ({ authenticationState, authUrlBase, redirectUrl,
|
|
14
|
+
export const AuthRequiredComponent: React.FC<IAuthRequiredComponentProps> = ({ authenticationState, authUrlBase, redirectUrl, children }) => {
|
|
16
15
|
const location = useLocation()
|
|
17
16
|
const queryParams = new URLSearchParams(location.search)
|
|
18
17
|
const authUuid = queryParams.get(AuthUtils.authUuidQueryStringName)
|
|
19
18
|
|
|
20
19
|
useEffect(() => {
|
|
21
|
-
if (!authenticationState.
|
|
20
|
+
if (!new AuthenticationStateHelper({ state: authenticationState, }).authenticated && !authenticationState.options?.loading) {
|
|
22
21
|
if (!authUuid) {
|
|
23
22
|
if (!authUrlBase.includes('/login'))
|
|
24
23
|
authUrlBase = `${authUrlBase}/login`
|
|
24
|
+
|
|
25
|
+
localStorage.clear()
|
|
26
|
+
sessionStorage.clear()
|
|
27
|
+
document.cookie.split(";").forEach(cookie => {
|
|
28
|
+
const name = cookie.split("=")[0].trim();
|
|
29
|
+
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
30
|
+
});
|
|
31
|
+
|
|
25
32
|
window.location.href = `${authUrlBase}?${AuthUtils.authToRedirectQueryStringName}=${encodeURIComponent(redirectUrl)}`
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
35
|
}, [authenticationState]);
|
|
29
36
|
|
|
30
|
-
if (!authenticationState.
|
|
37
|
+
if (!new AuthenticationStateHelper({ state: authenticationState, }).authenticated) {
|
|
31
38
|
return null;
|
|
32
39
|
}
|
|
33
40
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
|
1
|
+
import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
2
2
|
import { AuthenticationsApiClient, IAuthentication, IAuthenticationRequestBodyDefault, IAuthenticationRequestBodyFromGoogleToken, IAuthenticationRequestBodyFromUuid, IAuthenticationTokenData, IUser } from 'datacenter-lib-common-ts';
|
|
3
3
|
import { WebUtils } from 'fwork-jsts-common';
|
|
4
4
|
import { jwtDecode } from 'jwt-decode'; // dont use jsonwebtokens package here, its only for node projects
|
|
5
|
+
import moment from 'moment';
|
|
5
6
|
|
|
6
7
|
export interface IAuthenticationExt extends IAuthentication {
|
|
7
8
|
user: IUser
|
|
@@ -11,7 +12,7 @@ export interface IAuthenticationState {
|
|
|
11
12
|
options?: {
|
|
12
13
|
loading?: boolean,
|
|
13
14
|
},
|
|
14
|
-
payload?: IAuthenticationExt
|
|
15
|
+
payload?: IAuthenticationExt,
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const cookie = WebUtils.getCookie('@authenticationState')
|
|
@@ -27,7 +28,7 @@ export const authenticationStateLoadFromApi = createAsyncThunk(
|
|
|
27
28
|
|
|
28
29
|
onError?: (msg?: string) => void,
|
|
29
30
|
onSuccess?: (authentication?: IAuthentication) => void,
|
|
30
|
-
|
|
31
|
+
// }, { getState }) => {
|
|
31
32
|
}) => {
|
|
32
33
|
try {
|
|
33
34
|
let result: IAuthenticationState = {}
|
|
@@ -53,7 +54,7 @@ export const authenticationStateLoadFromApi = createAsyncThunk(
|
|
|
53
54
|
if (arg.onError)
|
|
54
55
|
arg.onError('Erro ao tentar autenticar')
|
|
55
56
|
|
|
56
|
-
return
|
|
57
|
+
return
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
)
|
|
@@ -62,7 +63,7 @@ export const authenticationSlice = createSlice({
|
|
|
62
63
|
name: 'authenticationSlice',
|
|
63
64
|
initialState: initState,
|
|
64
65
|
reducers: {
|
|
65
|
-
set: (state, action) => {
|
|
66
|
+
set: (state, action: PayloadAction<IAuthenticationState>) => {
|
|
66
67
|
state.payload = action.payload.payload
|
|
67
68
|
WebUtils.setCookie('@authenticationState', JSON.stringify(state), 1)
|
|
68
69
|
},
|
|
@@ -94,4 +95,28 @@ export const authenticationSlice = createSlice({
|
|
|
94
95
|
|
|
95
96
|
export const { logout: authenticationStateLogout, set: authenticationStateSet } = authenticationSlice.actions
|
|
96
97
|
|
|
97
|
-
export default authenticationSlice.reducer
|
|
98
|
+
export default authenticationSlice.reducer
|
|
99
|
+
|
|
100
|
+
export class AuthenticationStateHelper {
|
|
101
|
+
state: IAuthenticationState
|
|
102
|
+
|
|
103
|
+
constructor(args: {
|
|
104
|
+
state: IAuthenticationState
|
|
105
|
+
}) {
|
|
106
|
+
this.state = args.state
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get authenticated(): boolean {
|
|
110
|
+
let result = false
|
|
111
|
+
|
|
112
|
+
if (this.state.payload?.token)
|
|
113
|
+
try {
|
|
114
|
+
var decToken: IAuthenticationTokenData = jwtDecode(this.state.payload?.token)
|
|
115
|
+
result = (decToken.exp || 0) >= moment().unix()
|
|
116
|
+
} catch (error) {
|
|
117
|
+
result = false
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return result
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Divider, ListItemText, Menu, MenuItem, PopoverVirtualElement } from "@mui/material"
|
|
2
|
+
import { IUser } from "datacenter-lib-common-ts"
|
|
3
|
+
import React from "react"
|
|
4
|
+
import { MdLogout } from "react-icons/md"
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
user: IUser,
|
|
8
|
+
anchorEl?: Element | PopoverVirtualElement | (() => Element) | (() => PopoverVirtualElement) | null | undefined
|
|
9
|
+
open: boolean
|
|
10
|
+
onClose?: () => void
|
|
11
|
+
onLogOut?: () => void
|
|
12
|
+
onProfile?: () => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const UserDropdownMenu = ({
|
|
16
|
+
user,
|
|
17
|
+
anchorEl,
|
|
18
|
+
open,
|
|
19
|
+
onClose,
|
|
20
|
+
onLogOut,
|
|
21
|
+
onProfile,
|
|
22
|
+
}: Props) => {
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<Menu
|
|
26
|
+
anchorEl={anchorEl}
|
|
27
|
+
open={open}
|
|
28
|
+
onClose={onClose}
|
|
29
|
+
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
|
|
30
|
+
transformOrigin={{ vertical: "top", horizontal: "right" }}
|
|
31
|
+
PaperProps={{
|
|
32
|
+
sx: {
|
|
33
|
+
marginTop: .5,
|
|
34
|
+
minWidth: 260,
|
|
35
|
+
borderRadius: 2,
|
|
36
|
+
boxShadow: "0 8px 24px rgba(0,0,0,0.12)",
|
|
37
|
+
overflow: "hidden",
|
|
38
|
+
},
|
|
39
|
+
}}
|
|
40
|
+
MenuListProps={{ sx: { p: 0 } }}
|
|
41
|
+
>
|
|
42
|
+
<MenuItem
|
|
43
|
+
onClick={onProfile}
|
|
44
|
+
sx={{
|
|
45
|
+
gap: 1,
|
|
46
|
+
p: 2,
|
|
47
|
+
// py: 1.2,
|
|
48
|
+
fontWeight: 500,
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
<ListItemText
|
|
52
|
+
primary={user.name}
|
|
53
|
+
secondary={user.email}
|
|
54
|
+
/>
|
|
55
|
+
</MenuItem>
|
|
56
|
+
|
|
57
|
+
<Divider style={{margin: 0}}/>
|
|
58
|
+
|
|
59
|
+
{/* Logout */}
|
|
60
|
+
<MenuItem
|
|
61
|
+
onClick={onLogOut}
|
|
62
|
+
sx={{
|
|
63
|
+
gap: 1,
|
|
64
|
+
py: 1.2,
|
|
65
|
+
fontWeight: 500,
|
|
66
|
+
color: "error.main",
|
|
67
|
+
"&:hover": {
|
|
68
|
+
backgroundColor: "rgba(211, 47, 47, 0.08)",
|
|
69
|
+
},
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
<MdLogout size={20} />
|
|
73
|
+
Sair
|
|
74
|
+
</MenuItem>
|
|
75
|
+
</Menu>
|
|
76
|
+
</>
|
|
77
|
+
)
|
|
78
|
+
}
|
package/src/auth/userOptions.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Avatar, IconButton
|
|
1
|
+
import PersonIcon from "@mui/icons-material/Person"
|
|
2
|
+
import { Avatar, IconButton } from "@mui/material"
|
|
3
3
|
import { IUser } from "datacenter-lib-common-ts"
|
|
4
4
|
import React, { useState } from "react"
|
|
5
5
|
import { useDispatch } from 'react-redux'
|
|
6
6
|
import { authenticationStateLogout } from './authentication.slice'
|
|
7
|
+
import { UserDropdownMenu } from './userDropdownMenu'
|
|
7
8
|
|
|
8
9
|
export interface IUserOptionsComponentProps {
|
|
9
10
|
user: IUser,
|
|
@@ -17,38 +18,27 @@ export const UserOptionsComponent: React.FC<IUserOptionsComponentProps> = ({ use
|
|
|
17
18
|
const openMenu = Boolean(menuAnchor)
|
|
18
19
|
|
|
19
20
|
return <>
|
|
20
|
-
<
|
|
21
|
-
|
|
21
|
+
<UserDropdownMenu
|
|
22
|
+
user={user}
|
|
22
23
|
anchorEl={menuAnchor}
|
|
23
24
|
open={openMenu}
|
|
24
25
|
onClose={() => setAnchorElemnt(null)}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{user.name}
|
|
37
|
-
</MenuItem>
|
|
38
|
-
<MenuItem
|
|
39
|
-
style={{ display: 'flex', gap: 10 }}
|
|
40
|
-
onClick={() => {
|
|
41
|
-
dispatch(authenticationStateLogout())
|
|
42
|
-
if (onLogOut) onLogOut()
|
|
43
|
-
setAnchorElemnt(null)
|
|
44
|
-
}}
|
|
45
|
-
>
|
|
46
|
-
<LogoutIcon /> Sair
|
|
47
|
-
</MenuItem>
|
|
48
|
-
</Menu>
|
|
26
|
+
onLogOut={() => {
|
|
27
|
+
dispatch(authenticationStateLogout())
|
|
28
|
+
if (onLogOut) onLogOut()
|
|
29
|
+
setAnchorElemnt(null)
|
|
30
|
+
}}
|
|
31
|
+
onProfile={() => {
|
|
32
|
+
let authUrl = `${datacenterAuthBaseUrl}/profile`
|
|
33
|
+
window.open(authUrl, '_blank')?.focus()
|
|
34
|
+
setAnchorElemnt(null)
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
49
37
|
|
|
50
38
|
<IconButton
|
|
51
39
|
onClick={e => setAnchorElemnt(e.currentTarget)}
|
|
52
|
-
><Avatar src={user.imageUrl}
|
|
40
|
+
><Avatar src={user.imageUrl}>
|
|
41
|
+
<PersonIcon />
|
|
42
|
+
</Avatar></IconButton>
|
|
53
43
|
</>
|
|
54
44
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AuthCheckComponent, IAuthCheckComponentProps, } from './auth/authCheck'
|
|
2
|
-
import authenticationReducer, { authenticationStateLoadFromApi, IAuthenticationState, IAuthenticationExt, authenticationStateLogout, authenticationSlice, authenticationStateSet, } from './auth/authentication.slice'
|
|
2
|
+
import authenticationReducer, { authenticationStateLoadFromApi, AuthenticationStateHelper, IAuthenticationState, IAuthenticationExt, authenticationStateLogout, authenticationSlice, authenticationStateSet, } from './auth/authentication.slice'
|
|
3
3
|
import { AuthRequiredComponent, IAuthRequiredComponentProps, } from './auth/authRequired'
|
|
4
4
|
import { AuthUtils, } from './auth/authUtils'
|
|
5
5
|
import { UserOptionsComponent, IUserOptionsComponentProps, } from './auth/userOptions'
|
|
6
6
|
|
|
7
7
|
export {
|
|
8
8
|
AuthCheckComponent, IAuthCheckComponentProps,
|
|
9
|
-
authenticationReducer, authenticationStateLoadFromApi,
|
|
9
|
+
authenticationReducer, authenticationStateLoadFromApi, AuthenticationStateHelper, IAuthenticationExt, IAuthenticationState, authenticationStateLogout, authenticationSlice, authenticationStateSet,
|
|
10
10
|
AuthRequiredComponent, IAuthRequiredComponentProps,
|
|
11
11
|
AuthUtils,
|
|
12
12
|
UserOptionsComponent, IUserOptionsComponentProps,
|