@frontegg/react-hooks 6.0.3-alpha.4 → 6.2.1

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.
@@ -67,7 +67,7 @@ const HideChildrenIfFronteggRoutes = ({
67
67
  return null;
68
68
  }
69
69
 
70
- return _jsx(_Fragment, {
70
+ return /*#__PURE__*/_jsx(_Fragment, {
71
71
  children: children
72
72
  });
73
73
  };
@@ -100,12 +100,12 @@ const FronteggContent = ({
100
100
  }
101
101
 
102
102
  if (alwaysShowChildren) {
103
- return _jsx(_Fragment, {
103
+ return /*#__PURE__*/_jsx(_Fragment, {
104
104
  children: children
105
105
  });
106
106
  }
107
107
 
108
- return _jsx(HideChildrenIfFronteggRoutes, {
108
+ return /*#__PURE__*/_jsx(HideChildrenIfFronteggRoutes, {
109
109
  basename: app == null ? void 0 : app.options.basename,
110
110
  children: children
111
111
  });
@@ -119,7 +119,8 @@ export const FronteggStoreProvider = props => {
119
119
  app,
120
120
  contextOptions,
121
121
  setLoading: setLoadingProps
122
- } = props;
122
+ } = props; // TODO: make this optionals more readable
123
+
123
124
  const context = (_app$options$contextO = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.contextOptions) != null ? _app$options$contextO : contextOptions;
124
125
  const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options5 = app.options) == null ? void 0 : _app$options5.previewMode) != null ? _app$options$previewM : false;
125
126
  const authOptions = app != null && (_app$options6 = app.options) != null && _app$options6.authOptions ? _extends({}, app.options.authOptions, {
@@ -131,10 +132,10 @@ export const FronteggStoreProvider = props => {
131
132
  const store = useMemo(() => createFronteggStore({
132
133
  context: context
133
134
  }, app, previewMode, authOptions), [app, previewMode]);
134
- return _jsx(Provider, {
135
+ return /*#__PURE__*/_jsx(Provider, {
135
136
  context: FronteggStoreContext,
136
137
  store: store,
137
- children: _jsx(FronteggContent, {
138
+ children: /*#__PURE__*/_jsx(FronteggContent, {
138
139
  setLoading: setLoadingProps != null ? setLoadingProps : setLoading,
139
140
  app: app,
140
141
  children: children
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { createSelectorHook, createDispatchHook, createStoreHook } from 'react-redux';
3
- export const FronteggStoreContext = React.createContext(null);
3
+ export const FronteggStoreContext = /*#__PURE__*/React.createContext(null); // @ts-ignore
4
4
 
5
5
  if (process.env.NODE_ENV !== 'production') {
6
6
  FronteggStoreContext.displayName = 'FronteggStoreContext';
package/audits/hooks.js CHANGED
@@ -15,6 +15,10 @@ export const useAuditsActions = () => {
15
15
  const dispatch = useDispatch();
16
16
  return useMemo(() => bindActionCreators(auditsActions, dispatch), [auditsActions]);
17
17
  };
18
+ /**
19
+ * hooks helpers
20
+ */
21
+
18
22
  export const sliceReducerActionsBy = reducer => {
19
23
  const reducerKeys = Object.keys(reducer);
20
24
  const reducerActions = reducerKeys.map(key => ({
package/auth/hooks.js CHANGED
@@ -13,6 +13,24 @@ const defaultMapper = {
13
13
  export const useAuth = (stateMapper = defaultMapper.state) => {
14
14
  return useSelector(state => stateMapper(state[authStoreName]), shallowEqual);
15
15
  };
16
+ /**
17
+ * ```jsx
18
+ * export const MyFunctionComponent = () => {
19
+ * const { isAuthenticated, user } = useAuth();
20
+ * const loginWithRedirect = useLoginWithRedirect();
21
+ *
22
+ * if (!isAuthenticated) {
23
+ * loginWithRedirect();
24
+ * return <></>;
25
+ * }
26
+ *
27
+ * return (<div>Hello User {user.name}</div>);
28
+ * }
29
+ * ```
30
+ *
31
+ * use this frontegg hook function to get if user is "Authenticated"
32
+ */
33
+
16
34
  export const useLoginWithRedirect = () => {
17
35
  const dispatch = useDispatch();
18
36
  return useMemo(() => bindActionCreators(authActions.requestHostedLoginAuthorize, dispatch), [authActions.requestHostedLoginAuthorize]);
@@ -28,11 +46,34 @@ export const useOnRedirectTo = () => {
28
46
  return (_context$onRedirectTo = context == null ? void 0 : context.onRedirectTo) != null ? _context$onRedirectTo : ContextHolder.onRedirectTo;
29
47
  };
30
48
  export const useAuthRoutes = () => useAuth(state => _extends({}, state.routes));
49
+ /**
50
+ * ```jsx
51
+ * export const MyFunctionComponent = () => {
52
+ * const isAuthenticated = useIsAuthenticated();
53
+ * return isAuthenticated ? <div>Hello User</div> : <Redirect to={'/login'}/>
54
+ * }
55
+ * ```
56
+ *
57
+ * use this frontegg hook function to get if user is "Authenticated"
58
+ */
59
+
31
60
  export const useIsAuthenticated = () => useSelector(({
32
61
  [authStoreName]: {
33
62
  isAuthenticated
34
63
  }
35
64
  }) => isAuthenticated, shallowEqual);
65
+ /**
66
+ * ```jsx
67
+ * export const MyFunctionComponent = () => {
68
+ * const user = useAuthUser();
69
+ * return user ? <div>Hello {user.name}!</div> : <div>Hello Guest!</div>
70
+ * }
71
+ * ```
72
+ *
73
+ * use this frontegg hook function to get the authenticated user
74
+ * the return user is null if not authenticated
75
+ */
76
+
36
77
  export const useAuthUser = () => {
37
78
  const routes = useAuthRoutes();
38
79
  const onRedirectTo = useOnRedirectTo();
@@ -59,6 +100,10 @@ export const useAuthUserOrNull = () => {
59
100
  }), shallowEqual);
60
101
  return user || null;
61
102
  };
103
+ /**
104
+ * hooks helpers
105
+ */
106
+
62
107
  export const sliceReducerActionsBy = reducer => {
63
108
  const reducerKeys = Object.keys(reducer);
64
109
  const reducerActions = reducerKeys.map(key => ({
@@ -14,7 +14,7 @@ export const usePublicPolicySettings = (loadOnMount = false) => {
14
14
  loadPublicSecurityPolicy
15
15
  } = useSecurityPolicyActions();
16
16
  useEffect(() => {
17
- (loadOnMount || !policy) && loadPublicSecurityPolicy();
17
+ (loadOnMount || !policy) && loadPublicSecurityPolicy(); // eslint-disable-next-line react-hooks/exhaustive-deps
18
18
  }, [loadOnMount, loadPublicSecurityPolicy]);
19
19
  return {
20
20
  loading,
@@ -34,7 +34,7 @@ export const usePublicAuthStrategiesPolicySettings = (loadOnMount = false) => {
34
34
  loadPublicAuthStrategiesPolicy
35
35
  } = useSecurityPolicyActions();
36
36
  useEffect(() => {
37
- (loadOnMount || !policy) && loadPublicAuthStrategiesPolicy();
37
+ (loadOnMount || !policy) && loadPublicAuthStrategiesPolicy(); // eslint-disable-next-line react-hooks/exhaustive-deps
38
38
  }, [loadOnMount, loadPublicAuthStrategiesPolicy]);
39
39
  return {
40
40
  loading,
package/common/index.js CHANGED
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["urlStrategy", "onRedirectTo", "renderByRoute", "customLoader", "customStyles", "contextOptions"];
4
4
  import { createContext, useContext } from 'react';
5
- export const ShadowDomContext = createContext({});
5
+ export const ShadowDomContext = /*#__PURE__*/createContext({});
6
6
  export const useShadowDom = () => {
7
7
  const context = useContext(ShadowDomContext);
8
8
 
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.0.3-alpha.4
1
+ /** @license Frontegg v6.2.1
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -88,7 +88,7 @@ const HideChildrenIfFronteggRoutes = ({
88
88
  return null;
89
89
  }
90
90
 
91
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
91
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
92
92
  children: children
93
93
  });
94
94
  };
@@ -121,12 +121,12 @@ const FronteggContent = ({
121
121
  }
122
122
 
123
123
  if (alwaysShowChildren) {
124
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
124
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
125
125
  children: children
126
126
  });
127
127
  }
128
128
 
129
- return (0, _jsxRuntime.jsx)(HideChildrenIfFronteggRoutes, {
129
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(HideChildrenIfFronteggRoutes, {
130
130
  basename: app == null ? void 0 : app.options.basename,
131
131
  children: children
132
132
  });
@@ -140,7 +140,8 @@ const FronteggStoreProvider = props => {
140
140
  app,
141
141
  contextOptions,
142
142
  setLoading: setLoadingProps
143
- } = props;
143
+ } = props; // TODO: make this optionals more readable
144
+
144
145
  const context = (_app$options$contextO = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.contextOptions) != null ? _app$options$contextO : contextOptions;
145
146
  const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options5 = app.options) == null ? void 0 : _app$options5.previewMode) != null ? _app$options$previewM : false;
146
147
  const authOptions = app != null && (_app$options6 = app.options) != null && _app$options6.authOptions ? (0, _extends2.default)({}, app.options.authOptions, {
@@ -154,10 +155,10 @@ const FronteggStoreProvider = props => {
154
155
  const store = (0, _react.useMemo)(() => (0, _reduxStore.createFronteggStore)({
155
156
  context: context
156
157
  }, app, previewMode, authOptions), [app, previewMode]);
157
- return (0, _jsxRuntime.jsx)(Provider, {
158
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
158
159
  context: _FronteggStoreContext.FronteggStoreContext,
159
160
  store: store,
160
- children: (0, _jsxRuntime.jsx)(FronteggContent, {
161
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(FronteggContent, {
161
162
  setLoading: setLoadingProps != null ? setLoadingProps : setLoading,
162
163
  app: app,
163
164
  children: children
@@ -31,7 +31,8 @@ var _react = _interopRequireDefault(require("react"));
31
31
 
32
32
  var _reactRedux = require("react-redux");
33
33
 
34
- const FronteggStoreContext = _react.default.createContext(null);
34
+ const FronteggStoreContext = /*#__PURE__*/_react.default.createContext(null); // @ts-ignore
35
+
35
36
 
36
37
  exports.FronteggStoreContext = FronteggStoreContext;
37
38
 
@@ -31,6 +31,10 @@ const useAuditsActions = () => {
31
31
  const dispatch = (0, _FronteggStoreContext.useDispatch)();
32
32
  return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.auditsActions, dispatch), [_reduxStore.auditsActions]);
33
33
  };
34
+ /**
35
+ * hooks helpers
36
+ */
37
+
34
38
 
35
39
  exports.useAuditsActions = useAuditsActions;
36
40
 
@@ -29,6 +29,24 @@ const defaultMapper = {
29
29
  const useAuth = (stateMapper = defaultMapper.state) => {
30
30
  return (0, _FronteggStoreContext.useSelector)(state => stateMapper(state[_reduxStore.authStoreName]), _reactRedux.shallowEqual);
31
31
  };
32
+ /**
33
+ * ```jsx
34
+ * export const MyFunctionComponent = () => {
35
+ * const { isAuthenticated, user } = useAuth();
36
+ * const loginWithRedirect = useLoginWithRedirect();
37
+ *
38
+ * if (!isAuthenticated) {
39
+ * loginWithRedirect();
40
+ * return <></>;
41
+ * }
42
+ *
43
+ * return (<div>Hello User {user.name}</div>);
44
+ * }
45
+ * ```
46
+ *
47
+ * use this frontegg hook function to get if user is "Authenticated"
48
+ */
49
+
32
50
 
33
51
  exports.useAuth = useAuth;
34
52
 
@@ -56,6 +74,17 @@ const useOnRedirectTo = () => {
56
74
  exports.useOnRedirectTo = useOnRedirectTo;
57
75
 
58
76
  const useAuthRoutes = () => useAuth(state => (0, _extends2.default)({}, state.routes));
77
+ /**
78
+ * ```jsx
79
+ * export const MyFunctionComponent = () => {
80
+ * const isAuthenticated = useIsAuthenticated();
81
+ * return isAuthenticated ? <div>Hello User</div> : <Redirect to={'/login'}/>
82
+ * }
83
+ * ```
84
+ *
85
+ * use this frontegg hook function to get if user is "Authenticated"
86
+ */
87
+
59
88
 
60
89
  exports.useAuthRoutes = useAuthRoutes;
61
90
 
@@ -64,6 +93,18 @@ const useIsAuthenticated = () => (0, _FronteggStoreContext.useSelector)(({
64
93
  isAuthenticated
65
94
  }
66
95
  }) => isAuthenticated, _reactRedux.shallowEqual);
96
+ /**
97
+ * ```jsx
98
+ * export const MyFunctionComponent = () => {
99
+ * const user = useAuthUser();
100
+ * return user ? <div>Hello {user.name}!</div> : <div>Hello Guest!</div>
101
+ * }
102
+ * ```
103
+ *
104
+ * use this frontegg hook function to get the authenticated user
105
+ * the return user is null if not authenticated
106
+ */
107
+
67
108
 
68
109
  exports.useIsAuthenticated = useIsAuthenticated;
69
110
 
@@ -96,6 +137,10 @@ const useAuthUserOrNull = () => {
96
137
  }), _reactRedux.shallowEqual);
97
138
  return user || null;
98
139
  };
140
+ /**
141
+ * hooks helpers
142
+ */
143
+
99
144
 
100
145
  exports.useAuthUserOrNull = useAuthUserOrNull;
101
146
 
@@ -30,7 +30,7 @@ const usePublicPolicySettings = (loadOnMount = false) => {
30
30
  loadPublicSecurityPolicy
31
31
  } = useSecurityPolicyActions();
32
32
  (0, _react.useEffect)(() => {
33
- (loadOnMount || !policy) && loadPublicSecurityPolicy();
33
+ (loadOnMount || !policy) && loadPublicSecurityPolicy(); // eslint-disable-next-line react-hooks/exhaustive-deps
34
34
  }, [loadOnMount, loadPublicSecurityPolicy]);
35
35
  return {
36
36
  loading,
@@ -53,7 +53,7 @@ const usePublicAuthStrategiesPolicySettings = (loadOnMount = false) => {
53
53
  loadPublicAuthStrategiesPolicy
54
54
  } = useSecurityPolicyActions();
55
55
  (0, _react.useEffect)(() => {
56
- (loadOnMount || !policy) && loadPublicAuthStrategiesPolicy();
56
+ (loadOnMount || !policy) && loadPublicAuthStrategiesPolicy(); // eslint-disable-next-line react-hooks/exhaustive-deps
57
57
  }, [loadOnMount, loadPublicAuthStrategiesPolicy]);
58
58
  return {
59
59
  loading,
@@ -14,7 +14,7 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
14
14
  var _react = require("react");
15
15
 
16
16
  const _excluded = ["urlStrategy", "onRedirectTo", "renderByRoute", "customLoader", "customStyles", "contextOptions"];
17
- const ShadowDomContext = (0, _react.createContext)({});
17
+ const ShadowDomContext = /*#__PURE__*/(0, _react.createContext)({});
18
18
  exports.ShadowDomContext = ShadowDomContext;
19
19
 
20
20
  const useShadowDom = () => {
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.0.3-alpha.4
1
+ /** @license Frontegg v6.2.1
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@frontegg/react-hooks",
3
- "version": "6.0.3-alpha.4",
3
+ "version": "6.2.1",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.17.2",
9
- "@frontegg/redux-store": "6.0.3-alpha.4",
10
- "@frontegg/types": "6.0.3-alpha.4",
11
- "@types/react": "^17.0.0 || ^18.0.0",
9
+ "@frontegg/redux-store": "6.2.1",
10
+ "@frontegg/types": "6.2.1",
11
+ "@types/react": "*",
12
12
  "react-redux": "^7.x"
13
13
  },
14
14
  "sideEffects": false,