@frontegg/react-hooks 6.159.0 → 6.161.0-alpha.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/auth/hooks.d.ts CHANGED
@@ -49,6 +49,7 @@ export declare function useAuth<S>(stateMapper: AuthStateMapper<S>): S;
49
49
  * When using this option, you can have the user on the first load, and you can control when the user is redirected to the login page by using `loginWithRedirect`.
50
50
  */
51
51
  export declare const useLoginWithRedirect: () => AuthActions['requestHostedLoginAuthorize'];
52
+ export declare const useLoginWithRedirectV2: () => AuthActions['requestHostedLoginAuthorizeV2'];
52
53
  export declare const useAuthActions: () => AuthActions;
53
54
  export declare const useOnRedirectTo: () => (path: string, opts?: RedirectOptions | undefined) => void;
54
55
  export declare const useAuthRoutes: () => AuthPageRoutes;
package/auth/hooks.js CHANGED
@@ -59,6 +59,10 @@ export const useLoginWithRedirect = () => {
59
59
  const dispatch = useDispatch();
60
60
  return useMemo(() => bindActionCreators(authActions.requestHostedLoginAuthorize, dispatch), [authActions.requestHostedLoginAuthorize]);
61
61
  };
62
+ export const useLoginWithRedirectV2 = () => {
63
+ const dispatch = useDispatch();
64
+ return useMemo(() => bindActionCreators(authActions.requestHostedLoginAuthorizeV2, dispatch), [authActions.requestHostedLoginAuthorizeV2]);
65
+ };
62
66
  export const useAuthActions = () => {
63
67
  const dispatch = useDispatch();
64
68
  return useMemo(() => bindActionCreators(authActions, dispatch), [authActions]);
package/auth/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- export { useAuth, useAuthActions, useOnRedirectTo, useAuthRoutes, useIsAuthenticated, useAuthUser, useAuthUserOrNull, useLoginWithRedirect, } from './hooks';
1
+ export { useAuth, useAuthActions, useOnRedirectTo, useAuthRoutes, useIsAuthenticated, useAuthUser, useAuthUserOrNull, useLoginWithRedirect, useLoginWithRedirectV2, } from './hooks';
2
2
  export * from './acceptInvitation';
3
3
  export * from './activateAccount';
4
4
  export * from './apiTokens';
5
5
  export * from './forgotPassword';
6
6
  export * from './resetPhoneNumber';
7
7
  export * from './login';
8
+ export * from './stepUp';
8
9
  export * from './mfa';
9
10
  export * from './profile';
10
11
  export * from './signup';
package/auth/index.js CHANGED
@@ -1,10 +1,11 @@
1
- export { useAuth, useAuthActions, useOnRedirectTo, useAuthRoutes, useIsAuthenticated, useAuthUser, useAuthUserOrNull, useLoginWithRedirect } from './hooks';
1
+ export { useAuth, useAuthActions, useOnRedirectTo, useAuthRoutes, useIsAuthenticated, useAuthUser, useAuthUserOrNull, useLoginWithRedirect, useLoginWithRedirectV2 } from './hooks';
2
2
  export * from './acceptInvitation';
3
3
  export * from './activateAccount';
4
4
  export * from './apiTokens';
5
5
  export * from './forgotPassword';
6
6
  export * from './resetPhoneNumber';
7
7
  export * from './login';
8
+ export * from './stepUp';
8
9
  export * from './mfa';
9
10
  export * from './profile';
10
11
  export * from './signup';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The name of the query param that contains the max age of the step up
3
+ */
4
+ export declare const STEP_UP_MAX_AGE_PARAM_NAME = "maxAge";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The name of the query param that contains the max age of the step up
3
+ */
4
+ export const STEP_UP_MAX_AGE_PARAM_NAME = 'maxAge';
@@ -0,0 +1,2 @@
1
+ export * from './stepUp';
2
+ export * from './interfaces';
@@ -0,0 +1,2 @@
1
+ export * from './stepUp';
2
+ export * from './interfaces';
@@ -0,0 +1,14 @@
1
+ import { StepUpState } from '@frontegg/redux-store';
2
+ export declare type StepUpStateMapper<S> = (state: StepUpState) => S;
3
+ /**
4
+ * Step up options (for stepUp function)
5
+ */
6
+ export interface StepUpOptions {
7
+ maxAge?: number;
8
+ }
9
+ /**
10
+ * useIsSteppedUp hook options
11
+ */
12
+ export interface UseIsSteppedUpOptions {
13
+ maxAge?: number;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import { StepUpState, StepUpActions } from '@frontegg/redux-store';
2
+ import { RedirectOptions } from '@frontegg/rest-api';
3
+ import { StepUpStateMapper, UseIsSteppedUpOptions } from './interfaces';
4
+ export declare function useStepUpState(): StepUpState;
5
+ export declare function useStepUpState<S>(stateMapper: StepUpStateMapper<S>): S;
6
+ export declare const useStepUpActions: () => StepUpActions;
7
+ /**
8
+ * Redirects to the step up url with the max age param and set the redirect url in the local storage
9
+ * The redirect url will be used after the step up flow is done
10
+ * @param stepUpUrl - step up url to redirect to
11
+ * @param onRedirectTo - redirect to function
12
+ * @param maxAge - max age of step up
13
+ */
14
+ export declare const redirectByStepUpUrl: (stepUpUrl: string, onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void, maxAge?: number | undefined) => void;
15
+ /**
16
+ * @returns max age from the query param as a number or null if not exists
17
+ */
18
+ export declare const getMaxAgeFromQueryParam: () => number | undefined;
19
+ /**
20
+ * @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
21
+ */
22
+ export declare const useStepUp: () => any;
23
+ /**
24
+ * @param options.maxAge - max age of step up
25
+ * @returns true when the user is stepped up, false otherwise
26
+ */
27
+ export declare const useIsSteppedUp: ({ maxAge }?: UseIsSteppedUpOptions) => boolean;
@@ -0,0 +1,66 @@
1
+ import { FRONTEGG_AFTER_AUTH_REDIRECT_URL, stepUpReducers, stepUpActions, getSearchParam, isSteppedUp } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator, useAuthRoutes, useAuthUser, useOnRedirectTo } from '../hooks';
3
+ import { useCallback } from 'react';
4
+ import { STEP_UP_MAX_AGE_PARAM_NAME } from './consts';
5
+ const defaultMapper = state => state;
6
+ export function useStepUpState(stateMapper = defaultMapper) {
7
+ return stateHookGenerator(stateMapper, 'stepUpState');
8
+ }
9
+ export const useStepUpActions = () => reducerActionsGenerator(stepUpActions, stepUpReducers);
10
+
11
+ /**
12
+ * Redirects to the step up url with the max age param and set the redirect url in the local storage
13
+ * The redirect url will be used after the step up flow is done
14
+ * @param stepUpUrl - step up url to redirect to
15
+ * @param onRedirectTo - redirect to function
16
+ * @param maxAge - max age of step up
17
+ */
18
+ export const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
19
+ const encodedRedirectUrl = window.location.pathname + window.location.search;
20
+ const maxAgePart = maxAge !== undefined ? `?${STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}` : '';
21
+ window.localStorage.setItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL, encodedRedirectUrl);
22
+ onRedirectTo(`${stepUpUrl}${maxAgePart}`, {
23
+ refresh: false
24
+ });
25
+ };
26
+
27
+ /**
28
+ * @returns max age from the query param as a number or null if not exists
29
+ */
30
+ export const getMaxAgeFromQueryParam = () => {
31
+ const str = getSearchParam(STEP_UP_MAX_AGE_PARAM_NAME);
32
+ return str === undefined ? undefined : +str;
33
+ };
34
+
35
+ /**
36
+ * @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
37
+ */
38
+ export const useStepUp = () => {
39
+ const {
40
+ stepUpUrl
41
+ } = useAuthRoutes();
42
+ const onRedirectTo = useOnRedirectTo();
43
+ return useCallback(options => {
44
+ redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
45
+ }, [stepUpUrl, onRedirectTo]);
46
+ };
47
+
48
+ /**
49
+ * @param options.maxAge - max age of step up
50
+ * @returns true when the user is stepped up, false otherwise
51
+ */
52
+ export const useIsSteppedUp = ({
53
+ maxAge
54
+ } = {}) => {
55
+ const {
56
+ amr = [],
57
+ acr = '',
58
+ auth_time
59
+ } = useAuthUser();
60
+ return isSteppedUp({
61
+ amr,
62
+ acr,
63
+ auth_time,
64
+ maxAge
65
+ });
66
+ };
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.159.0
1
+ /** @license Frontegg v6.161.0-alpha.0
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.
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.stateHookGenerator = exports.sliceReducerActionsBy = exports.reducerActionsGenerator = void 0;
8
8
  exports.useAuth = useAuth;
9
- exports.useOnRedirectTo = exports.useLoginWithRedirect = exports.useIsAuthenticated = exports.useAuthUserOrNull = exports.useAuthUser = exports.useAuthRoutes = exports.useAuthActions = void 0;
9
+ exports.useOnRedirectTo = exports.useLoginWithRedirectV2 = exports.useLoginWithRedirect = exports.useIsAuthenticated = exports.useAuthUserOrNull = exports.useAuthUser = exports.useAuthRoutes = exports.useAuthActions = void 0;
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
11
  var _react = require("react");
12
12
  var _reduxStore = require("@frontegg/redux-store");
@@ -68,6 +68,11 @@ const useLoginWithRedirect = () => {
68
68
  return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.authActions.requestHostedLoginAuthorize, dispatch), [_reduxStore.authActions.requestHostedLoginAuthorize]);
69
69
  };
70
70
  exports.useLoginWithRedirect = useLoginWithRedirect;
71
+ const useLoginWithRedirectV2 = () => {
72
+ const dispatch = (0, _FronteggStoreContext.useDispatch)();
73
+ return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.authActions.requestHostedLoginAuthorizeV2, dispatch), [_reduxStore.authActions.requestHostedLoginAuthorizeV2]);
74
+ };
75
+ exports.useLoginWithRedirectV2 = useLoginWithRedirectV2;
71
76
  const useAuthActions = () => {
72
77
  const dispatch = (0, _FronteggStoreContext.useDispatch)();
73
78
  return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.authActions, dispatch), [_reduxStore.authActions]);
@@ -11,7 +11,8 @@ var _exportNames = {
11
11
  useIsAuthenticated: true,
12
12
  useAuthUser: true,
13
13
  useAuthUserOrNull: true,
14
- useLoginWithRedirect: true
14
+ useLoginWithRedirect: true,
15
+ useLoginWithRedirectV2: true
15
16
  };
16
17
  Object.defineProperty(exports, "useAuth", {
17
18
  enumerable: true,
@@ -55,6 +56,12 @@ Object.defineProperty(exports, "useLoginWithRedirect", {
55
56
  return _hooks.useLoginWithRedirect;
56
57
  }
57
58
  });
59
+ Object.defineProperty(exports, "useLoginWithRedirectV2", {
60
+ enumerable: true,
61
+ get: function () {
62
+ return _hooks.useLoginWithRedirectV2;
63
+ }
64
+ });
58
65
  Object.defineProperty(exports, "useOnRedirectTo", {
59
66
  enumerable: true,
60
67
  get: function () {
@@ -134,6 +141,18 @@ Object.keys(_login).forEach(function (key) {
134
141
  }
135
142
  });
136
143
  });
144
+ var _stepUp = require("./stepUp");
145
+ Object.keys(_stepUp).forEach(function (key) {
146
+ if (key === "default" || key === "__esModule") return;
147
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
148
+ if (key in exports && exports[key] === _stepUp[key]) return;
149
+ Object.defineProperty(exports, key, {
150
+ enumerable: true,
151
+ get: function () {
152
+ return _stepUp[key];
153
+ }
154
+ });
155
+ });
137
156
  var _mfa = require("./mfa");
138
157
  Object.keys(_mfa).forEach(function (key) {
139
158
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.STEP_UP_MAX_AGE_PARAM_NAME = void 0;
7
+ /**
8
+ * The name of the query param that contains the max age of the step up
9
+ */
10
+ const STEP_UP_MAX_AGE_PARAM_NAME = 'maxAge';
11
+ exports.STEP_UP_MAX_AGE_PARAM_NAME = STEP_UP_MAX_AGE_PARAM_NAME;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _stepUp = require("./stepUp");
7
+ Object.keys(_stepUp).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _stepUp[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _stepUp[key];
14
+ }
15
+ });
16
+ });
17
+ var _interfaces = require("./interfaces");
18
+ Object.keys(_interfaces).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _interfaces[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _interfaces[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useStepUpActions = exports.useStepUp = exports.useIsSteppedUp = exports.redirectByStepUpUrl = exports.getMaxAgeFromQueryParam = void 0;
7
+ exports.useStepUpState = useStepUpState;
8
+ var _reduxStore = require("@frontegg/redux-store");
9
+ var _hooks = require("../hooks");
10
+ var _react = require("react");
11
+ var _consts = require("./consts");
12
+ const defaultMapper = state => state;
13
+ function useStepUpState(stateMapper = defaultMapper) {
14
+ return (0, _hooks.stateHookGenerator)(stateMapper, 'stepUpState');
15
+ }
16
+ const useStepUpActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.stepUpActions, _reduxStore.stepUpReducers);
17
+
18
+ /**
19
+ * Redirects to the step up url with the max age param and set the redirect url in the local storage
20
+ * The redirect url will be used after the step up flow is done
21
+ * @param stepUpUrl - step up url to redirect to
22
+ * @param onRedirectTo - redirect to function
23
+ * @param maxAge - max age of step up
24
+ */
25
+ exports.useStepUpActions = useStepUpActions;
26
+ const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
27
+ const encodedRedirectUrl = window.location.pathname + window.location.search;
28
+ const maxAgePart = maxAge !== undefined ? `?${_consts.STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}` : '';
29
+ window.localStorage.setItem(_reduxStore.FRONTEGG_AFTER_AUTH_REDIRECT_URL, encodedRedirectUrl);
30
+ onRedirectTo(`${stepUpUrl}${maxAgePart}`, {
31
+ refresh: false
32
+ });
33
+ };
34
+
35
+ /**
36
+ * @returns max age from the query param as a number or null if not exists
37
+ */
38
+ exports.redirectByStepUpUrl = redirectByStepUpUrl;
39
+ const getMaxAgeFromQueryParam = () => {
40
+ const str = (0, _reduxStore.getSearchParam)(_consts.STEP_UP_MAX_AGE_PARAM_NAME);
41
+ return str === undefined ? undefined : +str;
42
+ };
43
+
44
+ /**
45
+ * @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
46
+ */
47
+ exports.getMaxAgeFromQueryParam = getMaxAgeFromQueryParam;
48
+ const useStepUp = () => {
49
+ const {
50
+ stepUpUrl
51
+ } = (0, _hooks.useAuthRoutes)();
52
+ const onRedirectTo = (0, _hooks.useOnRedirectTo)();
53
+ return (0, _react.useCallback)(options => {
54
+ redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
55
+ }, [stepUpUrl, onRedirectTo]);
56
+ };
57
+
58
+ /**
59
+ * @param options.maxAge - max age of step up
60
+ * @returns true when the user is stepped up, false otherwise
61
+ */
62
+ exports.useStepUp = useStepUp;
63
+ const useIsSteppedUp = ({
64
+ maxAge
65
+ } = {}) => {
66
+ const {
67
+ amr = [],
68
+ acr = '',
69
+ auth_time
70
+ } = (0, _hooks.useAuthUser)();
71
+ return (0, _reduxStore.isSteppedUp)({
72
+ amr,
73
+ acr,
74
+ auth_time,
75
+ maxAge
76
+ });
77
+ };
78
+ exports.useIsSteppedUp = useIsSteppedUp;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.159.0
1
+ /** @license Frontegg v6.161.0-alpha.0
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,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/react-hooks",
3
- "version": "6.159.0",
3
+ "version": "6.161.0-alpha.0",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.18.6",
9
- "@frontegg/redux-store": "6.159.0",
10
- "@frontegg/types": "6.159.0",
9
+ "@frontegg/redux-store": "6.161.0-alpha.0",
10
+ "@frontegg/types": "6.161.0-alpha.0",
11
11
  "@types/react": "*",
12
12
  "get-value": "^3.0.1",
13
13
  "react-redux": "^7.x"