@frontegg/react-hooks 6.155.0-alpha.0 → 6.155.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/index.d.ts +0 -1
- package/auth/index.js +0 -1
- package/index.js +1 -1
- package/node/auth/index.js +0 -12
- package/node/index.js +1 -1
- package/package.json +3 -3
- package/auth/stepUp.d.ts +0 -10
- package/auth/stepUp.js +0 -55
- package/node/auth/stepUp.js +0 -67
package/auth/index.d.ts
CHANGED
package/auth/index.js
CHANGED
package/index.js
CHANGED
package/node/auth/index.js
CHANGED
|
@@ -134,18 +134,6 @@ Object.keys(_login).forEach(function (key) {
|
|
|
134
134
|
}
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
|
-
var _stepUp = require("./stepUp");
|
|
138
|
-
Object.keys(_stepUp).forEach(function (key) {
|
|
139
|
-
if (key === "default" || key === "__esModule") return;
|
|
140
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
141
|
-
if (key in exports && exports[key] === _stepUp[key]) return;
|
|
142
|
-
Object.defineProperty(exports, key, {
|
|
143
|
-
enumerable: true,
|
|
144
|
-
get: function () {
|
|
145
|
-
return _stepUp[key];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
137
|
var _mfa = require("./mfa");
|
|
150
138
|
Object.keys(_mfa).forEach(function (key) {
|
|
151
139
|
if (key === "default" || key === "__esModule") return;
|
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react-hooks",
|
|
3
|
-
"version": "6.155.0
|
|
3
|
+
"version": "6.155.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.155.0
|
|
10
|
-
"@frontegg/types": "6.155.0
|
|
9
|
+
"@frontegg/redux-store": "6.155.0",
|
|
10
|
+
"@frontegg/types": "6.155.0",
|
|
11
11
|
"@types/react": "*",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"react-redux": "^7.x"
|
package/auth/stepUp.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { StepUpState, StepUpActions } from '@frontegg/redux-store';
|
|
2
|
-
import { RedirectOptions } from '@frontegg/rest-api';
|
|
3
|
-
export declare type StepUpStateMapper<S> = (state: StepUpState) => S;
|
|
4
|
-
export declare function useStepUpState(): StepUpState;
|
|
5
|
-
export declare function useStepUpState<S>(stateMapper: StepUpStateMapper<S>): S;
|
|
6
|
-
export declare const useStepUpActions: () => StepUpActions;
|
|
7
|
-
export declare const redirectByStepUpUrl: (stepUpUrl: string, onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void, maxAge?: number | undefined) => void;
|
|
8
|
-
export declare const getMaxAgeFromQueryParam: () => number | null;
|
|
9
|
-
export declare const useStepUp: () => any;
|
|
10
|
-
export declare const useIsSteppedUp: () => boolean;
|
package/auth/stepUp.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { STEP_UP_REDIRECT_URL_QUERY_PARAM, stepUpReducers, stepUpActions, getQueryParam } from '@frontegg/redux-store';
|
|
2
|
-
import { reducerActionsGenerator, stateHookGenerator, useAuth, useAuthRoutes, useOnRedirectTo } from './hooks';
|
|
3
|
-
import { useCallback } from 'react';
|
|
4
|
-
const defaultMapper = state => state;
|
|
5
|
-
const STEP_UP_MAX_AGE_PARAM_NAME = 'maxAge';
|
|
6
|
-
export function useStepUpState(stateMapper = defaultMapper) {
|
|
7
|
-
return stateHookGenerator(stateMapper, 'stepUpState');
|
|
8
|
-
}
|
|
9
|
-
export const useStepUpActions = () => reducerActionsGenerator(stepUpActions, stepUpReducers);
|
|
10
|
-
export const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
|
|
11
|
-
const encodedRedirectUrl = encodeURIComponent(window.location.pathname + window.location.search);
|
|
12
|
-
onRedirectTo(`${stepUpUrl}?${STEP_UP_REDIRECT_URL_QUERY_PARAM}=${encodedRedirectUrl}&${STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}`, {
|
|
13
|
-
refresh: false
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
export const getMaxAgeFromQueryParam = () => {
|
|
17
|
-
const str = getQueryParam(STEP_UP_MAX_AGE_PARAM_NAME);
|
|
18
|
-
return str === null ? null : +str;
|
|
19
|
-
};
|
|
20
|
-
export const useStepUp = () => {
|
|
21
|
-
// also custom url?
|
|
22
|
-
const {
|
|
23
|
-
stepUpUrl
|
|
24
|
-
} = useAuthRoutes();
|
|
25
|
-
const onRedirectTo = useOnRedirectTo();
|
|
26
|
-
|
|
27
|
-
// SHOULD CHECK IF USER IS AUTHENTICATED? If not what to do?
|
|
28
|
-
// WHAT TO DO IF USER IS NOT AUTHENTICATED AND ENTERED DIRECTLY TO THE ROUTE OF STEP UP?
|
|
29
|
-
|
|
30
|
-
return useCallback(options => {
|
|
31
|
-
// SSR handling?
|
|
32
|
-
|
|
33
|
-
// A hack because of double calls to useEffect.
|
|
34
|
-
// It keeps us also when there is a usage of multiple HOCs on the same page -> multiple calls to stepUp
|
|
35
|
-
// TODO no window for SSR - what to do?
|
|
36
|
-
if (window.location.search.indexOf(STEP_UP_REDIRECT_URL_QUERY_PARAM) !== -1) return;
|
|
37
|
-
redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
|
|
38
|
-
}, [stepUpUrl, onRedirectTo]);
|
|
39
|
-
};
|
|
40
|
-
const ACR_VALUE = 'http://schemas.openid.net/pape/policies/2007/06/multi-factor';
|
|
41
|
-
const AMR_MFA_VALUE = 'mfa';
|
|
42
|
-
const AMR_ADDITIONAL_VALUE = ['otp', 'sms', 'hwk'];
|
|
43
|
-
export const useIsSteppedUp = () => {
|
|
44
|
-
// only if don't have amr acr ?? max age???
|
|
45
|
-
const {
|
|
46
|
-
amr = [],
|
|
47
|
-
acr = ''
|
|
48
|
-
} = useAuth(({
|
|
49
|
-
user
|
|
50
|
-
}) => user || {});
|
|
51
|
-
const isACRValid = acr === ACR_VALUE;
|
|
52
|
-
const isAMRIncludesMFA = amr.indexOf(AMR_MFA_VALUE) !== -1;
|
|
53
|
-
const isAMRIncludesMethod = AMR_ADDITIONAL_VALUE.find(method => amr.indexOf(method)) !== undefined;
|
|
54
|
-
return isACRValid && isAMRIncludesMFA && isAMRIncludesMethod;
|
|
55
|
-
};
|
package/node/auth/stepUp.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
const defaultMapper = state => state;
|
|
12
|
-
const STEP_UP_MAX_AGE_PARAM_NAME = 'maxAge';
|
|
13
|
-
function useStepUpState(stateMapper = defaultMapper) {
|
|
14
|
-
return (0, _hooks.stateHookGenerator)(stateMapper, 'stepUpState');
|
|
15
|
-
}
|
|
16
|
-
const useStepUpActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.stepUpActions, _reduxStore.stepUpReducers);
|
|
17
|
-
exports.useStepUpActions = useStepUpActions;
|
|
18
|
-
const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
|
|
19
|
-
const encodedRedirectUrl = encodeURIComponent(window.location.pathname + window.location.search);
|
|
20
|
-
onRedirectTo(`${stepUpUrl}?${_reduxStore.STEP_UP_REDIRECT_URL_QUERY_PARAM}=${encodedRedirectUrl}&${STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}`, {
|
|
21
|
-
refresh: false
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
exports.redirectByStepUpUrl = redirectByStepUpUrl;
|
|
25
|
-
const getMaxAgeFromQueryParam = () => {
|
|
26
|
-
const str = (0, _reduxStore.getQueryParam)(STEP_UP_MAX_AGE_PARAM_NAME);
|
|
27
|
-
return str === null ? null : +str;
|
|
28
|
-
};
|
|
29
|
-
exports.getMaxAgeFromQueryParam = getMaxAgeFromQueryParam;
|
|
30
|
-
const useStepUp = () => {
|
|
31
|
-
// also custom url?
|
|
32
|
-
const {
|
|
33
|
-
stepUpUrl
|
|
34
|
-
} = (0, _hooks.useAuthRoutes)();
|
|
35
|
-
const onRedirectTo = (0, _hooks.useOnRedirectTo)();
|
|
36
|
-
|
|
37
|
-
// SHOULD CHECK IF USER IS AUTHENTICATED? If not what to do?
|
|
38
|
-
// WHAT TO DO IF USER IS NOT AUTHENTICATED AND ENTERED DIRECTLY TO THE ROUTE OF STEP UP?
|
|
39
|
-
|
|
40
|
-
return (0, _react.useCallback)(options => {
|
|
41
|
-
// SSR handling?
|
|
42
|
-
|
|
43
|
-
// A hack because of double calls to useEffect.
|
|
44
|
-
// It keeps us also when there is a usage of multiple HOCs on the same page -> multiple calls to stepUp
|
|
45
|
-
// TODO no window for SSR - what to do?
|
|
46
|
-
if (window.location.search.indexOf(_reduxStore.STEP_UP_REDIRECT_URL_QUERY_PARAM) !== -1) return;
|
|
47
|
-
redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
|
|
48
|
-
}, [stepUpUrl, onRedirectTo]);
|
|
49
|
-
};
|
|
50
|
-
exports.useStepUp = useStepUp;
|
|
51
|
-
const ACR_VALUE = 'http://schemas.openid.net/pape/policies/2007/06/multi-factor';
|
|
52
|
-
const AMR_MFA_VALUE = 'mfa';
|
|
53
|
-
const AMR_ADDITIONAL_VALUE = ['otp', 'sms', 'hwk'];
|
|
54
|
-
const useIsSteppedUp = () => {
|
|
55
|
-
// only if don't have amr acr ?? max age???
|
|
56
|
-
const {
|
|
57
|
-
amr = [],
|
|
58
|
-
acr = ''
|
|
59
|
-
} = (0, _hooks.useAuth)(({
|
|
60
|
-
user
|
|
61
|
-
}) => user || {});
|
|
62
|
-
const isACRValid = acr === ACR_VALUE;
|
|
63
|
-
const isAMRIncludesMFA = amr.indexOf(AMR_MFA_VALUE) !== -1;
|
|
64
|
-
const isAMRIncludesMethod = AMR_ADDITIONAL_VALUE.find(method => amr.indexOf(method)) !== undefined;
|
|
65
|
-
return isACRValid && isAMRIncludesMFA && isAMRIncludesMethod;
|
|
66
|
-
};
|
|
67
|
-
exports.useIsSteppedUp = useIsSteppedUp;
|