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