@frontegg/redux-store 6.155.0-alpha.5 → 6.155.0-alpha.7
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.
|
@@ -7,6 +7,18 @@ import { FRONTEGG_AFTER_AUTH_REDIRECT_URL } from '../../../constants';
|
|
|
7
7
|
import { isSteppedUp } from '../../StepUpState';
|
|
8
8
|
import { SHOULD_STEP_UP_KEY } from '../../StepUpState/consts';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @param url
|
|
12
|
+
* @returns url without the origin if it's the same origin as the current window origin
|
|
13
|
+
*/
|
|
14
|
+
function cleanUrlIfSameOrigin(url) {
|
|
15
|
+
var _window, _window2;
|
|
16
|
+
if (!url.startsWith((_window = window) == null ? void 0 : _window.location.origin)) {
|
|
17
|
+
return url;
|
|
18
|
+
}
|
|
19
|
+
return url.replace((_window2 = window) == null ? void 0 : _window2.location.origin, '');
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
/**
|
|
11
23
|
* @param customLoginAuthenticatedUrl custom login authenticated url if exists
|
|
12
24
|
* @returns the authenticated url to redirect to after auth navigation
|
|
@@ -32,12 +44,15 @@ function* getUrlForAfterAuthNavigation(customLoginAuthenticatedUrl) {
|
|
|
32
44
|
if (!finalUrl || [loginUrl, logoutUrl, socialLoginCallbackUrl, activateUrl].includes(finalUrl)) {
|
|
33
45
|
finalUrl = authenticatedUrl;
|
|
34
46
|
}
|
|
35
|
-
|
|
47
|
+
const redirectUrl = getRedirectUrl({
|
|
36
48
|
authenticatedUrl: finalUrl,
|
|
37
49
|
includeQueryParam,
|
|
38
50
|
enforceRedirectToSameSite,
|
|
39
51
|
allowedRedirectOrigins
|
|
40
52
|
});
|
|
53
|
+
|
|
54
|
+
// clean origin if it's the same origin as the current window origin to avoid refresh in afterAuthNavigationUtil
|
|
55
|
+
return cleanUrlIfSameOrigin(redirectUrl);
|
|
41
56
|
}
|
|
42
57
|
/**
|
|
43
58
|
* Utility to share after auth navigation flow between login and step up
|
|
@@ -57,7 +72,7 @@ export function* afterAuthNavigationUtil(resetStateAction, {
|
|
|
57
72
|
// we don't want to remove the FRONTEGG_AFTER_AUTH_REDIRECT_URL when we are in the step up flow
|
|
58
73
|
redirectUrl = forceStepUpUrl;
|
|
59
74
|
} else {
|
|
60
|
-
var
|
|
75
|
+
var _window3;
|
|
61
76
|
if (shouldStepUpDuringLogin) {
|
|
62
77
|
// getUrlForAfterAuthNavigation give priority to the redirectUrl
|
|
63
78
|
// avoiding use of getUrlForAfterAuthNavigation because we don't want to use the redirectUrl for magic link for example
|
|
@@ -69,7 +84,7 @@ export function* afterAuthNavigationUtil(resetStateAction, {
|
|
|
69
84
|
if (!redirectUrl) {
|
|
70
85
|
redirectUrl = yield call(getUrlForAfterAuthNavigation, customLoginAuthenticatedUrl);
|
|
71
86
|
}
|
|
72
|
-
(
|
|
87
|
+
(_window3 = window) == null ? void 0 : _window3.localStorage.removeItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL);
|
|
73
88
|
}
|
|
74
89
|
yield delay(200);
|
|
75
90
|
put(resetStateAction());
|
|
@@ -83,7 +98,7 @@ export function* afterAuthNavigationUtil(resetStateAction, {
|
|
|
83
98
|
* Handling also step up scenario when user silently logout to continue to step up
|
|
84
99
|
*/
|
|
85
100
|
export function* afterAuthNavigation() {
|
|
86
|
-
var
|
|
101
|
+
var _window4;
|
|
87
102
|
const {
|
|
88
103
|
routes: {
|
|
89
104
|
customLoginAuthenticatedUrl,
|
|
@@ -92,13 +107,13 @@ export function* afterAuthNavigation() {
|
|
|
92
107
|
} = yield select(state => state.auth);
|
|
93
108
|
|
|
94
109
|
// login with magic code, try to step up, no other mfa, invalid max age, force_enroll -> logout, login with first factor, not-stepped up jwt -> navigate to step up
|
|
95
|
-
const shouldStepUp = (
|
|
110
|
+
const shouldStepUp = (_window4 = window) == null ? void 0 : _window4.localStorage.getItem(SHOULD_STEP_UP_KEY);
|
|
96
111
|
const user = yield select(({
|
|
97
112
|
auth
|
|
98
113
|
}) => auth.user);
|
|
99
114
|
if (shouldStepUp) {
|
|
100
|
-
var
|
|
101
|
-
(
|
|
115
|
+
var _window5;
|
|
116
|
+
(_window5 = window) == null ? void 0 : _window5.localStorage.removeItem(SHOULD_STEP_UP_KEY);
|
|
102
117
|
}
|
|
103
118
|
if (stepUpUrl && shouldStepUp && !isSteppedUp(user)) {
|
|
104
119
|
yield call(afterAuthNavigationUtil, actions.resetLoginState, {
|
package/index.js
CHANGED
|
@@ -14,6 +14,18 @@ var _utils = require("../utils");
|
|
|
14
14
|
var _constants = require("../../../constants");
|
|
15
15
|
var _StepUpState = require("../../StepUpState");
|
|
16
16
|
var _consts = require("../../StepUpState/consts");
|
|
17
|
+
/**
|
|
18
|
+
* @param url
|
|
19
|
+
* @returns url without the origin if it's the same origin as the current window origin
|
|
20
|
+
*/
|
|
21
|
+
function cleanUrlIfSameOrigin(url) {
|
|
22
|
+
var _window, _window2;
|
|
23
|
+
if (!url.startsWith((_window = window) == null ? void 0 : _window.location.origin)) {
|
|
24
|
+
return url;
|
|
25
|
+
}
|
|
26
|
+
return url.replace((_window2 = window) == null ? void 0 : _window2.location.origin, '');
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
/**
|
|
18
30
|
* @param customLoginAuthenticatedUrl custom login authenticated url if exists
|
|
19
31
|
* @returns the authenticated url to redirect to after auth navigation
|
|
@@ -39,12 +51,15 @@ function* getUrlForAfterAuthNavigation(customLoginAuthenticatedUrl) {
|
|
|
39
51
|
if (!finalUrl || [loginUrl, logoutUrl, socialLoginCallbackUrl, activateUrl].includes(finalUrl)) {
|
|
40
52
|
finalUrl = authenticatedUrl;
|
|
41
53
|
}
|
|
42
|
-
|
|
54
|
+
const redirectUrl = (0, _utils.getRedirectUrl)({
|
|
43
55
|
authenticatedUrl: finalUrl,
|
|
44
56
|
includeQueryParam,
|
|
45
57
|
enforceRedirectToSameSite,
|
|
46
58
|
allowedRedirectOrigins
|
|
47
59
|
});
|
|
60
|
+
|
|
61
|
+
// clean origin if it's the same origin as the current window origin to avoid refresh in afterAuthNavigationUtil
|
|
62
|
+
return cleanUrlIfSameOrigin(redirectUrl);
|
|
48
63
|
}
|
|
49
64
|
/**
|
|
50
65
|
* Utility to share after auth navigation flow between login and step up
|
|
@@ -64,7 +79,7 @@ function* afterAuthNavigationUtil(resetStateAction, {
|
|
|
64
79
|
// we don't want to remove the FRONTEGG_AFTER_AUTH_REDIRECT_URL when we are in the step up flow
|
|
65
80
|
redirectUrl = forceStepUpUrl;
|
|
66
81
|
} else {
|
|
67
|
-
var
|
|
82
|
+
var _window3;
|
|
68
83
|
if (shouldStepUpDuringLogin) {
|
|
69
84
|
// getUrlForAfterAuthNavigation give priority to the redirectUrl
|
|
70
85
|
// avoiding use of getUrlForAfterAuthNavigation because we don't want to use the redirectUrl for magic link for example
|
|
@@ -76,7 +91,7 @@ function* afterAuthNavigationUtil(resetStateAction, {
|
|
|
76
91
|
if (!redirectUrl) {
|
|
77
92
|
redirectUrl = yield (0, _effects.call)(getUrlForAfterAuthNavigation, customLoginAuthenticatedUrl);
|
|
78
93
|
}
|
|
79
|
-
(
|
|
94
|
+
(_window3 = window) == null ? void 0 : _window3.localStorage.removeItem(_constants.FRONTEGG_AFTER_AUTH_REDIRECT_URL);
|
|
80
95
|
}
|
|
81
96
|
yield (0, _effects.delay)(200);
|
|
82
97
|
(0, _effects.put)(resetStateAction());
|
|
@@ -90,7 +105,7 @@ function* afterAuthNavigationUtil(resetStateAction, {
|
|
|
90
105
|
* Handling also step up scenario when user silently logout to continue to step up
|
|
91
106
|
*/
|
|
92
107
|
function* afterAuthNavigation() {
|
|
93
|
-
var
|
|
108
|
+
var _window4;
|
|
94
109
|
const {
|
|
95
110
|
routes: {
|
|
96
111
|
customLoginAuthenticatedUrl,
|
|
@@ -99,13 +114,13 @@ function* afterAuthNavigation() {
|
|
|
99
114
|
} = yield (0, _effects.select)(state => state.auth);
|
|
100
115
|
|
|
101
116
|
// login with magic code, try to step up, no other mfa, invalid max age, force_enroll -> logout, login with first factor, not-stepped up jwt -> navigate to step up
|
|
102
|
-
const shouldStepUp = (
|
|
117
|
+
const shouldStepUp = (_window4 = window) == null ? void 0 : _window4.localStorage.getItem(_consts.SHOULD_STEP_UP_KEY);
|
|
103
118
|
const user = yield (0, _effects.select)(({
|
|
104
119
|
auth
|
|
105
120
|
}) => auth.user);
|
|
106
121
|
if (shouldStepUp) {
|
|
107
|
-
var
|
|
108
|
-
(
|
|
122
|
+
var _window5;
|
|
123
|
+
(_window5 = window) == null ? void 0 : _window5.localStorage.removeItem(_consts.SHOULD_STEP_UP_KEY);
|
|
109
124
|
}
|
|
110
125
|
if (stepUpUrl && shouldStepUp && !(0, _StepUpState.isSteppedUp)(user)) {
|
|
111
126
|
yield (0, _effects.call)(afterAuthNavigationUtil, _reducer.actions.resetLoginState, {
|
package/node/index.js
CHANGED