@frontegg/react-hooks 6.69.0 → 6.70.0
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/FronteggProvider/index.js +2 -18
- package/FronteggStoreContext/index.js +2 -2
- package/audits/auditLogs.js +0 -2
- package/audits/auditsMetadata.js +0 -2
- package/audits/hooks.js +1 -2
- package/auth/acceptInvitation.js +1 -2
- package/auth/activateAccount.js +0 -2
- package/auth/apiTokens.js +0 -2
- package/auth/forgotPassword.js +0 -2
- package/auth/hooks.js +4 -8
- package/auth/impersonate.js +0 -2
- package/auth/login.js +0 -2
- package/auth/mfa.js +0 -2
- package/auth/profile.js +0 -2
- package/auth/provisioning.js +0 -2
- package/auth/resetPhoneNumber.js +0 -2
- package/auth/restrictions.js +4 -4
- package/auth/roles.js +0 -2
- package/auth/securityPolicy.js +4 -4
- package/auth/sessions.js +0 -2
- package/auth/sessionsPolicy.js +0 -2
- package/auth/signup.js +0 -2
- package/auth/socialLogin.js +0 -2
- package/auth/sso.js +0 -2
- package/auth/team.js +0 -2
- package/auth/tenants.js +0 -2
- package/common/index.d.ts +1 -1
- package/common/index.js +8 -10
- package/connectivity/hooks.js +0 -2
- package/flags/useFeatureFlags.js +0 -1
- package/index.js +1 -1
- package/node/FronteggProvider/index.js +2 -32
- package/node/FronteggStoreContext/index.js +2 -8
- package/node/audits/auditLogs.js +0 -6
- package/node/audits/auditsMetadata.js +0 -6
- package/node/audits/hooks.js +1 -18
- package/node/audits/index.js +0 -5
- package/node/auth/acceptInvitation.js +1 -6
- package/node/auth/activateAccount.js +0 -6
- package/node/auth/apiTokens.js +0 -6
- package/node/auth/forgotPassword.js +0 -6
- package/node/auth/hooks.js +4 -38
- package/node/auth/impersonate.js +0 -6
- package/node/auth/index.js +0 -41
- package/node/auth/login.js +0 -6
- package/node/auth/mfa.js +0 -6
- package/node/auth/profile.js +0 -9
- package/node/auth/provisioning.js +0 -6
- package/node/auth/resetPhoneNumber.js +0 -6
- package/node/auth/restrictions.js +4 -13
- package/node/auth/roles.js +0 -6
- package/node/auth/securityPolicy.js +4 -13
- package/node/auth/sessions.js +0 -6
- package/node/auth/sessionsPolicy.js +0 -6
- package/node/auth/signup.js +0 -6
- package/node/auth/socialLogin.js +0 -6
- package/node/auth/sso.js +0 -6
- package/node/auth/team.js +0 -6
- package/node/auth/tenants.js +0 -6
- package/node/common/index.js +8 -19
- package/node/connectivity/hooks.js +0 -8
- package/node/connectivity/index.js +0 -1
- package/node/flags/index.js +0 -2
- package/node/flags/useFeatureFlags.js +0 -4
- package/node/index.js +1 -19
- package/node/subscriptions/hooks.js +0 -46
- package/node/subscriptions/index.js +0 -2
- package/node/vendor/hooks.js +0 -8
- package/node/vendor/index.js +0 -1
- package/package.json +3 -3
- package/subscriptions/hooks.js +0 -4
- package/vendor/hooks.js +0 -2
|
@@ -1,34 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.FronteggStoreProvider = void 0;
|
|
9
|
-
|
|
10
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
-
|
|
12
9
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
13
|
-
|
|
14
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
|
-
|
|
16
11
|
var _reduxStore = require("@frontegg/redux-store");
|
|
17
|
-
|
|
18
12
|
var _restApi = require("@frontegg/rest-api");
|
|
19
|
-
|
|
20
13
|
var _auth = require("../auth");
|
|
21
|
-
|
|
22
14
|
var _FronteggStoreContext = require("../FronteggStoreContext");
|
|
23
|
-
|
|
24
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
|
-
|
|
26
16
|
const _excluded = ["authenticatedUrl", "signUpSuccessUrl"];
|
|
27
|
-
|
|
28
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
|
-
|
|
30
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
|
-
|
|
32
19
|
const defaultSetLoading = loading => {
|
|
33
20
|
if (loading) {
|
|
34
21
|
document.body.classList.add('frontegg-loading');
|
|
@@ -36,7 +23,6 @@ const defaultSetLoading = loading => {
|
|
|
36
23
|
document.body.classList.remove('frontegg-loading');
|
|
37
24
|
}
|
|
38
25
|
};
|
|
39
|
-
|
|
40
26
|
const HideChildrenIfFronteggRoutes = ({
|
|
41
27
|
children,
|
|
42
28
|
basename
|
|
@@ -50,7 +36,6 @@ const HideChildrenIfFronteggRoutes = ({
|
|
|
50
36
|
uriRef.current = window.location.pathname;
|
|
51
37
|
setUri(document.location.pathname);
|
|
52
38
|
}
|
|
53
|
-
|
|
54
39
|
animationFrameRef.current = window.requestAnimationFrame(checker);
|
|
55
40
|
}, []);
|
|
56
41
|
(0, _react.useEffect)(() => {
|
|
@@ -73,23 +58,19 @@ const HideChildrenIfFronteggRoutes = ({
|
|
|
73
58
|
}, [checker, setUri]);
|
|
74
59
|
const calculatedBasename = basename ? basename.endsWith('/') ? basename.substring(0, basename.length - 1) : '' : '';
|
|
75
60
|
const checkRoutes = (0, _objectWithoutPropertiesLoose2.default)(routes, _excluded);
|
|
76
|
-
|
|
77
61
|
if (Object.values(checkRoutes).map(url => `${calculatedBasename}${url}`).indexOf(uri) !== -1) {
|
|
78
62
|
return null;
|
|
79
63
|
}
|
|
80
|
-
|
|
81
64
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
82
65
|
children: children
|
|
83
66
|
});
|
|
84
67
|
};
|
|
85
|
-
|
|
86
68
|
const FronteggContent = ({
|
|
87
69
|
children,
|
|
88
70
|
app,
|
|
89
71
|
setLoading
|
|
90
72
|
}) => {
|
|
91
73
|
var _app$options, _app$options2;
|
|
92
|
-
|
|
93
74
|
const {
|
|
94
75
|
isLoading
|
|
95
76
|
} = (0, _auth.useAuth)(({
|
|
@@ -101,56 +82,46 @@ const FronteggContent = ({
|
|
|
101
82
|
const isNextJS = (app == null ? void 0 : (_app$options2 = app.options) == null ? void 0 : _app$options2.framework) === 'nextjs';
|
|
102
83
|
const alwaysShowChildren = customLoginBox || isNextJS;
|
|
103
84
|
const loadingRef = (0, _react.useRef)(undefined);
|
|
104
|
-
|
|
105
85
|
if (isLoading !== loadingRef.current && !isNextJS) {
|
|
106
86
|
loadingRef.current = isLoading;
|
|
107
87
|
setLoading(isLoading);
|
|
108
88
|
}
|
|
109
|
-
|
|
110
89
|
if (isLoading && !isNextJS) {
|
|
111
90
|
return null;
|
|
112
91
|
}
|
|
113
|
-
|
|
114
92
|
if (alwaysShowChildren) {
|
|
115
93
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
116
94
|
children: children
|
|
117
95
|
});
|
|
118
96
|
}
|
|
119
|
-
|
|
120
97
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(HideChildrenIfFronteggRoutes, {
|
|
121
98
|
basename: app == null ? void 0 : app.options.basename,
|
|
122
99
|
children: children
|
|
123
100
|
});
|
|
124
101
|
};
|
|
125
|
-
|
|
126
102
|
const FronteggStoreProvider = props => {
|
|
127
103
|
var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options5, _app$options6;
|
|
128
|
-
|
|
129
104
|
const {
|
|
130
105
|
children,
|
|
131
106
|
app,
|
|
132
107
|
contextOptions,
|
|
133
108
|
setLoading = defaultSetLoading
|
|
134
|
-
} = props;
|
|
109
|
+
} = props;
|
|
135
110
|
|
|
111
|
+
// TODO: make this optionals more readable
|
|
136
112
|
const context = (_app$options$contextO = app == null ? void 0 : (_app$options3 = app.options) == null ? void 0 : _app$options3.contextOptions) != null ? _app$options$contextO : contextOptions;
|
|
137
|
-
|
|
138
113
|
if (!context) {
|
|
139
114
|
throw Error('contextOptions must not be null or undefined');
|
|
140
115
|
}
|
|
141
|
-
|
|
142
116
|
const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.previewMode) != null ? _app$options$previewM : false;
|
|
143
117
|
const authOptions = app != null && (_app$options5 = app.options) != null && _app$options5.authOptions ? (0, _extends2.default)({}, app.options.authOptions, {
|
|
144
118
|
hostedLoginBox: app.options.hostedLoginBox
|
|
145
119
|
}) : {
|
|
146
120
|
hostedLoginBox: app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.hostedLoginBox
|
|
147
121
|
};
|
|
148
|
-
|
|
149
122
|
_restApi.ContextHolder.setContext(context);
|
|
150
|
-
|
|
151
123
|
const store = (0, _react.useMemo)(() => {
|
|
152
124
|
var _app$options7;
|
|
153
|
-
|
|
154
125
|
return (0, _reduxStore.createFronteggStore)({
|
|
155
126
|
context
|
|
156
127
|
}, app, previewMode, authOptions, undefined, false, app == null ? void 0 : (_app$options7 = app.options) == null ? void 0 : _app$options7.urlStrategy);
|
|
@@ -165,5 +136,4 @@ const FronteggStoreProvider = props => {
|
|
|
165
136
|
})
|
|
166
137
|
});
|
|
167
138
|
};
|
|
168
|
-
|
|
169
139
|
exports.FronteggStoreProvider = FronteggStoreProvider;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -20,20 +19,15 @@ Object.defineProperty(exports, "shallowEqual", {
|
|
|
20
19
|
}
|
|
21
20
|
});
|
|
22
21
|
exports.useStore = exports.useSelector = exports.useDispatch = void 0;
|
|
23
|
-
|
|
24
22
|
var _react = _interopRequireDefault(require("react"));
|
|
25
|
-
|
|
26
23
|
var _reactRedux = require("react-redux");
|
|
24
|
+
const FronteggStoreContext = /*#__PURE__*/_react.default.createContext(null);
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
// @ts-ignore
|
|
31
27
|
exports.FronteggStoreContext = FronteggStoreContext;
|
|
32
|
-
|
|
33
28
|
if (process.env.NODE_ENV !== 'production') {
|
|
34
29
|
FronteggStoreContext.displayName = 'FronteggStoreContext';
|
|
35
30
|
}
|
|
36
|
-
|
|
37
31
|
const useSelector = (0, _reactRedux.createSelectorHook)(FronteggStoreContext);
|
|
38
32
|
exports.useSelector = useSelector;
|
|
39
33
|
const useDispatch = (0, _reactRedux.createDispatchHook)(FronteggStoreContext);
|
package/node/audits/auditLogs.js
CHANGED
|
@@ -5,17 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useAuditLogsActions = void 0;
|
|
7
7
|
exports.useAuditLogsState = useAuditLogsState;
|
|
8
|
-
|
|
9
8
|
var _hooks = require("./hooks");
|
|
10
|
-
|
|
11
9
|
var _reduxStore = require("@frontegg/redux-store");
|
|
12
|
-
|
|
13
10
|
const defaultMapper = state => state;
|
|
14
|
-
|
|
15
11
|
function useAuditLogsState(stateMapper = defaultMapper) {
|
|
16
12
|
return (0, _hooks.stateHookGenerator)(stateMapper, 'auditLogsState');
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
const useAuditLogsActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.auditLogsActions, _reduxStore.auditLogsReducers);
|
|
20
|
-
|
|
21
15
|
exports.useAuditLogsActions = useAuditLogsActions;
|
|
@@ -5,17 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useAuditsMetadataActions = void 0;
|
|
7
7
|
exports.useAuditsMetadataState = useAuditsMetadataState;
|
|
8
|
-
|
|
9
8
|
var _reduxStore = require("@frontegg/redux-store");
|
|
10
|
-
|
|
11
9
|
var _hooks = require("./hooks");
|
|
12
|
-
|
|
13
10
|
const defaultMapper = state => state;
|
|
14
|
-
|
|
15
11
|
function useAuditsMetadataState(stateMapper = defaultMapper) {
|
|
16
12
|
return (0, _hooks.stateHookGenerator)(stateMapper, 'auditsMetadataState');
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
const useAuditsMetadataActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.auditsMetadataActions, _reduxStore.auditsMetadataReducers);
|
|
20
|
-
|
|
21
15
|
exports.useAuditsMetadataActions = useAuditsMetadataActions;
|
package/node/audits/hooks.js
CHANGED
|
@@ -1,43 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.useAuditsActions = exports.stateHookGenerator = exports.sliceReducerActionsBy = exports.reducerActionsGenerator = void 0;
|
|
9
8
|
exports.useAuditsState = useAuditsState;
|
|
10
|
-
|
|
11
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
|
-
|
|
13
10
|
var _react = require("react");
|
|
14
|
-
|
|
15
11
|
var _reduxStore = require("@frontegg/redux-store");
|
|
16
|
-
|
|
17
12
|
var _reactRedux = require("react-redux");
|
|
18
|
-
|
|
19
13
|
var _FronteggStoreContext = require("../FronteggStoreContext");
|
|
20
|
-
|
|
21
14
|
const defaultMapper = {
|
|
22
15
|
state: state => state,
|
|
23
16
|
actions: actions => actions
|
|
24
17
|
};
|
|
25
|
-
|
|
26
18
|
function useAuditsState(stateMapper = defaultMapper.state) {
|
|
27
19
|
return (0, _FronteggStoreContext.useSelector)(state => stateMapper(state[_reduxStore.auditsStoreName]), _reactRedux.shallowEqual);
|
|
28
20
|
}
|
|
29
|
-
|
|
30
21
|
const useAuditsActions = () => {
|
|
31
22
|
const dispatch = (0, _FronteggStoreContext.useDispatch)();
|
|
32
23
|
return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.auditsActions, dispatch), [_reduxStore.auditsActions]);
|
|
33
24
|
};
|
|
25
|
+
|
|
34
26
|
/**
|
|
35
27
|
* hooks helpers
|
|
36
28
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
29
|
exports.useAuditsActions = useAuditsActions;
|
|
40
|
-
|
|
41
30
|
const sliceReducerActionsBy = reducer => {
|
|
42
31
|
const reducerKeys = Object.keys(reducer);
|
|
43
32
|
const reducerActions = reducerKeys.map(key => ({
|
|
@@ -45,22 +34,16 @@ const sliceReducerActionsBy = reducer => {
|
|
|
45
34
|
}));
|
|
46
35
|
return reducerActions.reduce((p, n) => (0, _extends2.default)({}, p, n), {});
|
|
47
36
|
};
|
|
48
|
-
|
|
49
37
|
exports.sliceReducerActionsBy = sliceReducerActionsBy;
|
|
50
|
-
|
|
51
38
|
const stateHookGenerator = (stateMapper, subState) => {
|
|
52
39
|
return (0, _FronteggStoreContext.useSelector)(state => {
|
|
53
40
|
var _stateMapper;
|
|
54
|
-
|
|
55
41
|
return (_stateMapper = stateMapper == null ? void 0 : stateMapper(state[_reduxStore.auditsStoreName][subState])) != null ? _stateMapper : state[_reduxStore.auditsStoreName][subState];
|
|
56
42
|
}, _reactRedux.shallowEqual);
|
|
57
43
|
};
|
|
58
|
-
|
|
59
44
|
exports.stateHookGenerator = stateHookGenerator;
|
|
60
|
-
|
|
61
45
|
const reducerActionsGenerator = (actions, reducers) => {
|
|
62
46
|
const dispatch = (0, _FronteggStoreContext.useDispatch)();
|
|
63
47
|
return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)((0, _extends2.default)({}, actions, sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
|
|
64
48
|
};
|
|
65
|
-
|
|
66
49
|
exports.reducerActionsGenerator = reducerActionsGenerator;
|
package/node/audits/index.js
CHANGED
|
@@ -19,11 +19,8 @@ Object.defineProperty(exports, "useAuditsState", {
|
|
|
19
19
|
return _hooks.useAuditsState;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
|
|
23
22
|
var _hooks = require("./hooks");
|
|
24
|
-
|
|
25
23
|
var _auditLogs = require("./auditLogs");
|
|
26
|
-
|
|
27
24
|
Object.keys(_auditLogs).forEach(function (key) {
|
|
28
25
|
if (key === "default" || key === "__esModule") return;
|
|
29
26
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -35,9 +32,7 @@ Object.keys(_auditLogs).forEach(function (key) {
|
|
|
35
32
|
}
|
|
36
33
|
});
|
|
37
34
|
});
|
|
38
|
-
|
|
39
35
|
var _auditsMetadata = require("./auditsMetadata");
|
|
40
|
-
|
|
41
36
|
Object.keys(_auditsMetadata).forEach(function (key) {
|
|
42
37
|
if (key === "default" || key === "__esModule") return;
|
|
43
38
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -5,17 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useAcceptInvitationActions = void 0;
|
|
7
7
|
exports.useAcceptInvitationState = useAcceptInvitationState;
|
|
8
|
-
|
|
9
8
|
var _reduxStore = require("@frontegg/redux-store");
|
|
10
|
-
|
|
11
9
|
var _hooks = require("./hooks");
|
|
12
|
-
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
11
|
const defaultMapper = state => state;
|
|
14
|
-
|
|
15
12
|
function useAcceptInvitationState(stateMapper = defaultMapper) {
|
|
16
13
|
return (0, _hooks.stateHookGenerator)(stateMapper, 'acceptInvitationState');
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
const useAcceptInvitationActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.acceptInvitationActions, _reduxStore.acceptInvitationReducers);
|
|
20
|
-
|
|
21
16
|
exports.useAcceptInvitationActions = useAcceptInvitationActions;
|
|
@@ -5,17 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useActivateAccountActions = void 0;
|
|
7
7
|
exports.useActivateAccountState = useActivateAccountState;
|
|
8
|
-
|
|
9
8
|
var _reduxStore = require("@frontegg/redux-store");
|
|
10
|
-
|
|
11
9
|
var _hooks = require("./hooks");
|
|
12
|
-
|
|
13
10
|
const defaultMapper = state => state;
|
|
14
|
-
|
|
15
11
|
function useActivateAccountState(stateMapper = defaultMapper) {
|
|
16
12
|
return (0, _hooks.stateHookGenerator)(stateMapper, 'activateState');
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
const useActivateAccountActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.activateAccountActions, _reduxStore.activateAccountReducers);
|
|
20
|
-
|
|
21
15
|
exports.useActivateAccountActions = useActivateAccountActions;
|
package/node/auth/apiTokens.js
CHANGED
|
@@ -5,17 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useApiTokensActions = void 0;
|
|
7
7
|
exports.useApiTokensState = useApiTokensState;
|
|
8
|
-
|
|
9
8
|
var _reduxStore = require("@frontegg/redux-store");
|
|
10
|
-
|
|
11
9
|
var _hooks = require("./hooks");
|
|
12
|
-
|
|
13
10
|
const defaultMapper = state => state;
|
|
14
|
-
|
|
15
11
|
function useApiTokensState(stateMapper = defaultMapper) {
|
|
16
12
|
return (0, _hooks.stateHookGenerator)(stateMapper, 'apiTokensState');
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
const useApiTokensActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.apiTokensActions, _reduxStore.apiTokensReducers);
|
|
20
|
-
|
|
21
15
|
exports.useApiTokensActions = useApiTokensActions;
|
|
@@ -5,17 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useForgotPasswordActions = void 0;
|
|
7
7
|
exports.useForgotPasswordState = useForgotPasswordState;
|
|
8
|
-
|
|
9
8
|
var _reduxStore = require("@frontegg/redux-store");
|
|
10
|
-
|
|
11
9
|
var _hooks = require("./hooks");
|
|
12
|
-
|
|
13
10
|
const defaultMapper = state => state;
|
|
14
|
-
|
|
15
11
|
function useForgotPasswordState(stateMapper = defaultMapper) {
|
|
16
12
|
return (0, _hooks.stateHookGenerator)(stateMapper, 'forgotPasswordState');
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
const useForgotPasswordActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.forgotPasswordActions, _reduxStore.forgotPasswordReducers);
|
|
20
|
-
|
|
21
15
|
exports.useForgotPasswordActions = useForgotPasswordActions;
|
package/node/auth/hooks.js
CHANGED
|
@@ -1,36 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.stateHookGenerator = exports.sliceReducerActionsBy = exports.reducerActionsGenerator = void 0;
|
|
9
8
|
exports.useAuth = useAuth;
|
|
10
9
|
exports.useOnRedirectTo = exports.useLoginWithRedirect = exports.useIsAuthenticated = exports.useAuthUserOrNull = exports.useAuthUser = exports.useAuthRoutes = exports.useAuthActions = void 0;
|
|
11
|
-
|
|
12
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
11
|
var _react = require("react");
|
|
15
|
-
|
|
16
12
|
var _reduxStore = require("@frontegg/redux-store");
|
|
17
|
-
|
|
18
13
|
var _reactRedux = require("react-redux");
|
|
19
|
-
|
|
20
14
|
var _FronteggStoreContext = require("../FronteggStoreContext");
|
|
21
|
-
|
|
22
15
|
var _restApi = require("@frontegg/rest-api");
|
|
23
|
-
|
|
24
16
|
var _common = require("../common");
|
|
25
|
-
|
|
26
17
|
const defaultMapper = {
|
|
27
18
|
state: state => state,
|
|
28
19
|
actions: actions => actions
|
|
29
20
|
};
|
|
30
|
-
|
|
31
21
|
function useAuth(stateMapper = defaultMapper.state) {
|
|
32
22
|
return (0, _FronteggStoreContext.useSelector)(state => stateMapper(state[_reduxStore.authStoreName]), _reactRedux.shallowEqual);
|
|
33
23
|
}
|
|
24
|
+
|
|
34
25
|
/**
|
|
35
26
|
* ```jsx
|
|
36
27
|
* export const MyFunctionComponent = () => {
|
|
@@ -48,32 +39,24 @@ function useAuth(stateMapper = defaultMapper.state) {
|
|
|
48
39
|
*
|
|
49
40
|
* use this frontegg hook function to get if user is "Authenticated"
|
|
50
41
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
42
|
const useLoginWithRedirect = () => {
|
|
54
43
|
const dispatch = (0, _FronteggStoreContext.useDispatch)();
|
|
55
44
|
return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.authActions.requestHostedLoginAuthorize, dispatch), [_reduxStore.authActions.requestHostedLoginAuthorize]);
|
|
56
45
|
};
|
|
57
|
-
|
|
58
46
|
exports.useLoginWithRedirect = useLoginWithRedirect;
|
|
59
|
-
|
|
60
47
|
const useAuthActions = () => {
|
|
61
48
|
const dispatch = (0, _FronteggStoreContext.useDispatch)();
|
|
62
49
|
return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.authActions, dispatch), [_reduxStore.authActions]);
|
|
63
50
|
};
|
|
64
|
-
|
|
65
51
|
exports.useAuthActions = useAuthActions;
|
|
66
|
-
|
|
67
52
|
const useOnRedirectTo = () => {
|
|
68
53
|
var _context$onRedirectTo;
|
|
69
|
-
|
|
70
54
|
const context = (0, _react.useContext)(_common.ShadowDomContext);
|
|
71
55
|
return (_context$onRedirectTo = context == null ? void 0 : context.onRedirectTo) != null ? _context$onRedirectTo : _restApi.ContextHolder.onRedirectTo;
|
|
72
56
|
};
|
|
73
|
-
|
|
74
57
|
exports.useOnRedirectTo = useOnRedirectTo;
|
|
75
|
-
|
|
76
58
|
const useAuthRoutes = () => useAuth(state => (0, _extends2.default)({}, state.routes));
|
|
59
|
+
|
|
77
60
|
/**
|
|
78
61
|
* ```jsx
|
|
79
62
|
* export const MyFunctionComponent = () => {
|
|
@@ -84,15 +67,13 @@ const useAuthRoutes = () => useAuth(state => (0, _extends2.default)({}, state.ro
|
|
|
84
67
|
*
|
|
85
68
|
* use this frontegg hook function to get if user is "Authenticated"
|
|
86
69
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
70
|
exports.useAuthRoutes = useAuthRoutes;
|
|
90
|
-
|
|
91
71
|
const useIsAuthenticated = () => (0, _FronteggStoreContext.useSelector)(({
|
|
92
72
|
[_reduxStore.authStoreName]: {
|
|
93
73
|
isAuthenticated
|
|
94
74
|
}
|
|
95
75
|
}) => isAuthenticated, _reactRedux.shallowEqual);
|
|
76
|
+
|
|
96
77
|
/**
|
|
97
78
|
* ```jsx
|
|
98
79
|
* export const MyFunctionComponent = () => {
|
|
@@ -104,29 +85,22 @@ const useIsAuthenticated = () => (0, _FronteggStoreContext.useSelector)(({
|
|
|
104
85
|
* use this frontegg hook function to get the authenticated user
|
|
105
86
|
* the return user is null if not authenticated
|
|
106
87
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
88
|
exports.useIsAuthenticated = useIsAuthenticated;
|
|
110
|
-
|
|
111
89
|
const useAuthUser = () => {
|
|
112
90
|
const routes = useAuthRoutes();
|
|
113
91
|
const onRedirectTo = useOnRedirectTo();
|
|
114
92
|
const user = useAuthUserOrNull();
|
|
115
93
|
const isSSR = typeof window === 'undefined';
|
|
116
94
|
const noUser = {};
|
|
117
|
-
|
|
118
95
|
if (user == null && !isSSR) {
|
|
119
96
|
onRedirectTo(routes.loginUrl, {
|
|
120
97
|
refresh: true
|
|
121
98
|
});
|
|
122
99
|
return noUser;
|
|
123
100
|
}
|
|
124
|
-
|
|
125
101
|
return user || noUser;
|
|
126
102
|
};
|
|
127
|
-
|
|
128
103
|
exports.useAuthUser = useAuthUser;
|
|
129
|
-
|
|
130
104
|
const useAuthUserOrNull = () => {
|
|
131
105
|
const {
|
|
132
106
|
user
|
|
@@ -139,13 +113,11 @@ const useAuthUserOrNull = () => {
|
|
|
139
113
|
}), _reactRedux.shallowEqual);
|
|
140
114
|
return user || null;
|
|
141
115
|
};
|
|
116
|
+
|
|
142
117
|
/**
|
|
143
118
|
* hooks helpers
|
|
144
119
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
120
|
exports.useAuthUserOrNull = useAuthUserOrNull;
|
|
148
|
-
|
|
149
121
|
const sliceReducerActionsBy = reducer => {
|
|
150
122
|
const reducerKeys = Object.keys(reducer);
|
|
151
123
|
const reducerActions = reducerKeys.map(key => ({
|
|
@@ -153,22 +125,16 @@ const sliceReducerActionsBy = reducer => {
|
|
|
153
125
|
}));
|
|
154
126
|
return reducerActions.reduce((p, n) => (0, _extends2.default)({}, p, n), {});
|
|
155
127
|
};
|
|
156
|
-
|
|
157
128
|
exports.sliceReducerActionsBy = sliceReducerActionsBy;
|
|
158
|
-
|
|
159
129
|
const stateHookGenerator = (stateMapper, subState) => {
|
|
160
130
|
return (0, _FronteggStoreContext.useSelector)(state => {
|
|
161
131
|
var _stateMapper;
|
|
162
|
-
|
|
163
132
|
return (_stateMapper = stateMapper == null ? void 0 : stateMapper(state[_reduxStore.authStoreName][subState])) != null ? _stateMapper : state[_reduxStore.authStoreName][subState];
|
|
164
133
|
}, _reactRedux.shallowEqual);
|
|
165
134
|
};
|
|
166
|
-
|
|
167
135
|
exports.stateHookGenerator = stateHookGenerator;
|
|
168
|
-
|
|
169
136
|
const reducerActionsGenerator = (actions, reducers) => {
|
|
170
137
|
const dispatch = (0, _FronteggStoreContext.useDispatch)();
|
|
171
138
|
return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)((0, _extends2.default)({}, actions, sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
|
|
172
139
|
};
|
|
173
|
-
|
|
174
140
|
exports.reducerActionsGenerator = reducerActionsGenerator;
|
package/node/auth/impersonate.js
CHANGED
|
@@ -5,17 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useImpersonateActions = void 0;
|
|
7
7
|
exports.useImpersonateState = useImpersonateState;
|
|
8
|
-
|
|
9
8
|
var _reduxStore = require("@frontegg/redux-store");
|
|
10
|
-
|
|
11
9
|
var _hooks = require("./hooks");
|
|
12
|
-
|
|
13
10
|
const defaultMapper = state => state;
|
|
14
|
-
|
|
15
11
|
function useImpersonateState(stateMapper = defaultMapper) {
|
|
16
12
|
return (0, _hooks.stateHookGenerator)(stateMapper, 'impersonateState');
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
const useImpersonateActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.impersonateActions, _reduxStore.impersonateReducers);
|
|
20
|
-
|
|
21
15
|
exports.useImpersonateActions = useImpersonateActions;
|