@frontegg/react-hooks 6.165.0-alpha.13 → 6.165.0-alpha.14

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.
@@ -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';
@@ -1,2 +1,14 @@
1
1
  import { StepUpState } from '@frontegg/redux-store';
2
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
+ }
@@ -1,8 +1,17 @@
1
- import { StepUpState, StepUpActions, IsSteppedUpOptions } from '@frontegg/redux-store';
2
- import { StepUpStateMapper } from './interfaces';
1
+ import { StepUpState, StepUpActions } from '@frontegg/redux-store';
2
+ import { RedirectOptions } from '@frontegg/rest-api';
3
+ import { StepUpStateMapper, UseIsSteppedUpOptions } from './interfaces';
3
4
  export declare function useStepUpState(): StepUpState;
4
5
  export declare function useStepUpState<S>(stateMapper: StepUpStateMapper<S>): S;
5
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;
6
15
  /**
7
16
  * @returns max age from the query param as a number or null if not exists
8
17
  */
@@ -15,4 +24,4 @@ export declare const useStepUp: () => any;
15
24
  * @param options.maxAge - max age of step up
16
25
  * @returns true when the user is stepped up, false otherwise
17
26
  */
18
- export declare const useIsSteppedUp: (options?: IsSteppedUpOptions) => boolean;
27
+ export declare const useIsSteppedUp: ({ maxAge }?: UseIsSteppedUpOptions) => boolean;
@@ -1,12 +1,29 @@
1
- import { stepUpReducers, stepUpActions, getSearchParam, isSteppedUp, STEP_UP_MAX_AGE_PARAM_NAME, redirectByStepUpUrl } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator, useAuth, useAuthRoutes, useAuthUserOrNull, useOnRedirectTo } from '../hooks';
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
3
  import { useCallback } from 'react';
4
+ import { STEP_UP_MAX_AGE_PARAM_NAME } from './consts';
4
5
  const defaultMapper = state => state;
5
6
  export function useStepUpState(stateMapper = defaultMapper) {
6
7
  return stateHookGenerator(stateMapper, 'stepUpState');
7
8
  }
8
9
  export const useStepUpActions = () => reducerActionsGenerator(stepUpActions, stepUpReducers);
9
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
+
10
27
  /**
11
28
  * @returns max age from the query param as a number or null if not exists
12
29
  */
@@ -22,27 +39,28 @@ export const useStepUp = () => {
22
39
  const {
23
40
  stepUpUrl
24
41
  } = useAuthRoutes();
25
- const {
26
- hostedLoginBox
27
- } = useAuth();
28
- const {
29
- stepUpHostedLogin
30
- } = useStepUpActions();
31
42
  const onRedirectTo = useOnRedirectTo();
32
43
  return useCallback(options => {
33
- if (hostedLoginBox) {
34
- stepUpHostedLogin(options || {});
35
- return;
36
- }
37
44
  redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
38
- }, [stepUpUrl, onRedirectTo, stepUpHostedLogin, hostedLoginBox]);
45
+ }, [stepUpUrl, onRedirectTo]);
39
46
  };
40
47
 
41
48
  /**
42
49
  * @param options.maxAge - max age of step up
43
50
  * @returns true when the user is stepped up, false otherwise
44
51
  */
45
- export const useIsSteppedUp = (options = {}) => {
46
- const user = useAuthUserOrNull();
47
- return isSteppedUp(user, options);
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
+ });
48
66
  };
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.165.0-alpha.13
1
+ /** @license Frontegg v6.165.0-alpha.14
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.
@@ -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;
@@ -3,11 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useStepUpActions = exports.useStepUp = exports.useIsSteppedUp = exports.getMaxAgeFromQueryParam = void 0;
6
+ exports.useStepUpActions = exports.useStepUp = exports.useIsSteppedUp = exports.redirectByStepUpUrl = exports.getMaxAgeFromQueryParam = void 0;
7
7
  exports.useStepUpState = useStepUpState;
8
8
  var _reduxStore = require("@frontegg/redux-store");
9
9
  var _hooks = require("../hooks");
10
10
  var _react = require("react");
11
+ var _consts = require("./consts");
11
12
  const defaultMapper = state => state;
12
13
  function useStepUpState(stateMapper = defaultMapper) {
13
14
  return (0, _hooks.stateHookGenerator)(stateMapper, 'stepUpState');
@@ -15,11 +16,28 @@ function useStepUpState(stateMapper = defaultMapper) {
15
16
  const useStepUpActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.stepUpActions, _reduxStore.stepUpReducers);
16
17
 
17
18
  /**
18
- * @returns max age from the query param as a number or null if not exists
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
19
24
  */
20
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;
21
39
  const getMaxAgeFromQueryParam = () => {
22
- const str = (0, _reduxStore.getSearchParam)(_reduxStore.STEP_UP_MAX_AGE_PARAM_NAME);
40
+ const str = (0, _reduxStore.getSearchParam)(_consts.STEP_UP_MAX_AGE_PARAM_NAME);
23
41
  return str === undefined ? undefined : +str;
24
42
  };
25
43
 
@@ -31,20 +49,10 @@ const useStepUp = () => {
31
49
  const {
32
50
  stepUpUrl
33
51
  } = (0, _hooks.useAuthRoutes)();
34
- const {
35
- hostedLoginBox
36
- } = (0, _hooks.useAuth)();
37
- const {
38
- stepUpHostedLogin
39
- } = useStepUpActions();
40
52
  const onRedirectTo = (0, _hooks.useOnRedirectTo)();
41
53
  return (0, _react.useCallback)(options => {
42
- if (hostedLoginBox) {
43
- stepUpHostedLogin(options || {});
44
- return;
45
- }
46
- (0, _reduxStore.redirectByStepUpUrl)(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
47
- }, [stepUpUrl, onRedirectTo, stepUpHostedLogin, hostedLoginBox]);
54
+ redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
55
+ }, [stepUpUrl, onRedirectTo]);
48
56
  };
49
57
 
50
58
  /**
@@ -52,8 +60,19 @@ const useStepUp = () => {
52
60
  * @returns true when the user is stepped up, false otherwise
53
61
  */
54
62
  exports.useStepUp = useStepUp;
55
- const useIsSteppedUp = (options = {}) => {
56
- const user = (0, _hooks.useAuthUserOrNull)();
57
- return (0, _reduxStore.isSteppedUp)(user, options);
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
+ });
58
77
  };
59
78
  exports.useIsSteppedUp = useIsSteppedUp;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.165.0-alpha.13
1
+ /** @license Frontegg v6.165.0-alpha.14
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.165.0-alpha.13",
3
+ "version": "6.165.0-alpha.14",
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.165.0-alpha.13",
10
- "@frontegg/types": "6.165.0-alpha.13",
9
+ "@frontegg/redux-store": "6.165.0-alpha.14",
10
+ "@frontegg/types": "6.165.0-alpha.14",
11
11
  "@types/react": "*",
12
12
  "get-value": "^3.0.1",
13
13
  "react-redux": "^7.x"