@frontegg/redux-store 7.11.0-alpha.0 → 7.12.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/ActivateAccountState/actions.js +1 -4
- package/auth/LoginState/actions/afterAuthNavigation.actions.js +12 -10
- package/auth/LoginState/actions/handleVerifyMFAResponse.actions.js +1 -2
- package/auth/LoginState/actions/hostedLoginAuthorize.actions.js +10 -10
- package/auth/LoginState/actions/index.js +24 -23
- package/auth/LoginState/actions/mfaRequiredState.actions.js +1 -2
- package/auth/LoginState/actions/mfaWithAuthenticator.actions.js +1 -2
- package/auth/LoginState/helpers.js +4 -5
- package/auth/PasskeysState/actions.js +2 -3
- package/auth/SocialLoginState/actions.js +3 -4
- package/auth/StepUpState/actions/generateStepUpSession.actions.js +1 -3
- package/auth/StepUpState/actions/stepUpHostedLogin.actions.js +2 -3
- package/auth/StepUpState/helpers.d.ts +2 -2
- package/auth/StepUpState/helpers.js +6 -7
- package/helpers/gtm.js +2 -4
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +2 -1
- package/helpers/random.js +1 -2
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/interfaces.d.ts +11 -0
- package/node/auth/ActivateAccountState/actions.js +1 -4
- package/node/auth/LoginState/actions/afterAuthNavigation.actions.js +12 -10
- package/node/auth/LoginState/actions/handleVerifyMFAResponse.actions.js +1 -2
- package/node/auth/LoginState/actions/hostedLoginAuthorize.actions.js +10 -10
- package/node/auth/LoginState/actions/index.js +22 -21
- package/node/auth/LoginState/actions/mfaRequiredState.actions.js +1 -2
- package/node/auth/LoginState/actions/mfaWithAuthenticator.actions.js +1 -2
- package/node/auth/LoginState/helpers.js +4 -5
- package/node/auth/PasskeysState/actions.js +2 -3
- package/node/auth/SocialLoginState/actions.js +3 -4
- package/node/auth/StepUpState/actions/generateStepUpSession.actions.js +1 -2
- package/node/auth/StepUpState/actions/stepUpHostedLogin.actions.js +2 -3
- package/node/auth/StepUpState/helpers.js +6 -7
- package/node/helpers/gtm.js +2 -4
- package/node/helpers/index.js +11 -0
- package/node/helpers/random.js +1 -2
- package/node/index.js +12 -1
- package/node/toolkit/FronteggNativeModule.js +4 -10
- package/node/toolkit/index.js +2 -26
- package/node/toolkit/store.js +3 -1
- package/node/valtio/utils/devtools.js +1 -1
- package/package.json +1 -1
- package/toolkit/FronteggNativeModule.js +4 -10
- package/toolkit/index.d.ts +0 -3
- package/toolkit/index.js +1 -4
- package/toolkit/store.js +3 -1
- package/valtio/utils/devtools.js +1 -1
- package/node/toolkit/LocalStorage.js +0 -84
- package/node/toolkit/SessionStorage.js +0 -84
- package/node/toolkit/WindowLocation.js +0 -291
- package/toolkit/LocalStorage.d.ts +0 -45
- package/toolkit/LocalStorage.js +0 -77
- package/toolkit/SessionStorage.d.ts +0 -45
- package/toolkit/SessionStorage.js +0 -77
- package/toolkit/WindowLocation.d.ts +0 -160
- package/toolkit/WindowLocation.js +0 -284
|
@@ -77,10 +77,7 @@ export default ((store, api, sharedActions) => {
|
|
|
77
77
|
} = _await$api$auth$activ,
|
|
78
78
|
rest = _objectWithoutPropertiesLoose(_await$api$auth$activ, _excluded2);
|
|
79
79
|
if (user.redirectLocation) {
|
|
80
|
-
|
|
81
|
-
replace: true,
|
|
82
|
-
refresh: true
|
|
83
|
-
});
|
|
80
|
+
window.location.href = user.redirectLocation;
|
|
84
81
|
return;
|
|
85
82
|
}
|
|
86
83
|
if (isMfaRequired(user, store.root.appName)) {
|
|
@@ -3,7 +3,6 @@ import { getPathAndSearchParamsFromUrl, getRedirectUrl, isAbsoluteUrl } from '..
|
|
|
3
3
|
import { FRONTEGG_AFTER_AUTH_REDIRECT_URL } from '../../../constants';
|
|
4
4
|
import { SHOULD_STEP_UP_KEY } from '../../StepUpState/consts';
|
|
5
5
|
import { delay } from '../../../helpers';
|
|
6
|
-
import { LocalStorage, WindowLocation } from '../../../toolkit';
|
|
7
6
|
import { isSteppedUp } from '../../StepUpState/helpers';
|
|
8
7
|
export default ((store, api, sharedActions) => {
|
|
9
8
|
const actions = sharedActions;
|
|
@@ -16,10 +15,11 @@ export default ((store, api, sharedActions) => {
|
|
|
16
15
|
* In case the url is equal to the window.location.origin, it will return an empty string
|
|
17
16
|
*/
|
|
18
17
|
function cleanUrlIfSameOrigin(url) {
|
|
19
|
-
|
|
18
|
+
var _window, _window2;
|
|
19
|
+
if (!url.startsWith((_window = window) == null ? void 0 : _window.location.origin)) {
|
|
20
20
|
return url;
|
|
21
21
|
}
|
|
22
|
-
return url.replace(
|
|
22
|
+
return url.replace((_window2 = window) == null ? void 0 : _window2.location.origin, '');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -70,11 +70,11 @@ export default ((store, api, sharedActions) => {
|
|
|
70
70
|
socialLoginCallbackUrl,
|
|
71
71
|
activateUrl
|
|
72
72
|
} = routes;
|
|
73
|
-
let finalUrl =
|
|
73
|
+
let finalUrl = window.localStorage.getItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL);
|
|
74
74
|
if (!finalUrl || [loginUrl, logoutUrl, socialLoginCallbackUrl, activateUrl].includes(finalUrl)) {
|
|
75
75
|
finalUrl = authenticatedUrl;
|
|
76
76
|
}
|
|
77
|
-
const redirectUrl =
|
|
77
|
+
const redirectUrl = getRedirectUrl({
|
|
78
78
|
authenticatedUrl: finalUrl,
|
|
79
79
|
includeQueryParam,
|
|
80
80
|
enforceRedirectToSameSite,
|
|
@@ -108,10 +108,11 @@ export default ((store, api, sharedActions) => {
|
|
|
108
108
|
// we don't want to remove the FRONTEGG_AFTER_AUTH_REDIRECT_URL when we are in the step up flow
|
|
109
109
|
redirectUrl = forceStepUpUrl;
|
|
110
110
|
} else {
|
|
111
|
+
var _window3;
|
|
111
112
|
if (shouldStepUpDuringLogin) {
|
|
112
113
|
// getUrlForAfterAuthNavigation give priority to the redirectUrl
|
|
113
114
|
// avoiding use of getUrlForAfterAuthNavigation because we don't want to use the redirectUrl for magic link for example
|
|
114
|
-
const localStorageRedirectUrl =
|
|
115
|
+
const localStorageRedirectUrl = window.localStorage.getItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL);
|
|
115
116
|
if (localStorageRedirectUrl && !isAbsoluteUrl(localStorageRedirectUrl)) {
|
|
116
117
|
redirectUrl = localStorageRedirectUrl;
|
|
117
118
|
}
|
|
@@ -122,7 +123,7 @@ export default ((store, api, sharedActions) => {
|
|
|
122
123
|
preventRedirectUrlOriginCleaning
|
|
123
124
|
});
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
+
(_window3 = window) == null ? void 0 : _window3.localStorage.removeItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL);
|
|
126
127
|
}
|
|
127
128
|
await delay(200);
|
|
128
129
|
await resetStateAction();
|
|
@@ -136,17 +137,18 @@ export default ((store, api, sharedActions) => {
|
|
|
136
137
|
* Handling also step up scenario when user silently logout to continue to step up
|
|
137
138
|
*/
|
|
138
139
|
const afterAuthNavigation = async payload => {
|
|
139
|
-
var _payload$preventRedir;
|
|
140
|
+
var _window4, _payload$preventRedir;
|
|
140
141
|
const {
|
|
141
142
|
customLoginAuthenticatedUrl,
|
|
142
143
|
stepUpUrl
|
|
143
144
|
} = store.auth.routes;
|
|
144
145
|
|
|
145
146
|
// 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
|
|
146
|
-
const shouldStepUp =
|
|
147
|
+
const shouldStepUp = (_window4 = window) == null ? void 0 : _window4.localStorage.getItem(SHOULD_STEP_UP_KEY);
|
|
147
148
|
const user = store.auth.user;
|
|
148
149
|
if (shouldStepUp) {
|
|
149
|
-
|
|
150
|
+
var _window5;
|
|
151
|
+
(_window5 = window) == null ? void 0 : _window5.localStorage.removeItem(SHOULD_STEP_UP_KEY);
|
|
150
152
|
}
|
|
151
153
|
if (stepUpUrl && shouldStepUp && !isSteppedUp(user)) {
|
|
152
154
|
return afterAuthNavigationUtil(actions.resetLoginState, {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FeatureFlags } from '@frontegg/rest-api';
|
|
2
2
|
import { MFAStep } from '../../MfaState/interfaces';
|
|
3
3
|
import { LoginFlow, LoginStep } from '../interfaces';
|
|
4
|
-
import { LocalStorage } from '../../../toolkit';
|
|
5
4
|
export default function (store, api, sharedActions) {
|
|
6
5
|
const actions = sharedActions;
|
|
7
6
|
|
|
@@ -73,7 +72,7 @@ export default function (store, api, sharedActions) {
|
|
|
73
72
|
loading: false
|
|
74
73
|
});
|
|
75
74
|
if (user.id) {
|
|
76
|
-
|
|
75
|
+
localStorage.setItem('userId', user.id);
|
|
77
76
|
}
|
|
78
77
|
const isAuthenticated = !!user.accessToken;
|
|
79
78
|
actions.setAuthState({
|
|
@@ -4,7 +4,6 @@ import { HOSTED_LOGIN_VERIFIER_KEY } from '../../../constants';
|
|
|
4
4
|
import { getBaseNameWithoutSlashSuffix, getSearchParam, isOauthCallbackRoute, TENANT_ID_PARAM_KEY } from '../helpers';
|
|
5
5
|
import { getUri, isSteppedUp } from '../../helpers';
|
|
6
6
|
import { SHOULD_STEP_UP_KEY } from '../../StepUpState/consts';
|
|
7
|
-
import { WindowLocation, LocalStorage } from '../../../toolkit';
|
|
8
7
|
export default ((store, api, sharedActions) => {
|
|
9
8
|
const actions = sharedActions;
|
|
10
9
|
|
|
@@ -46,9 +45,9 @@ export default ((store, api, sharedActions) => {
|
|
|
46
45
|
const code_challenge = await generateCodeChallenge(code_verifier);
|
|
47
46
|
|
|
48
47
|
// We are saving the verifier in session storage to be able to validate the response
|
|
49
|
-
|
|
48
|
+
localStorage.setItem(HOSTED_LOGIN_VERIFIER_KEY, code_verifier);
|
|
50
49
|
const basename = getBaseNameWithoutSlashSuffix(store);
|
|
51
|
-
let redirectUrl = `${
|
|
50
|
+
let redirectUrl = `${window.location.origin}${urlStrategy === 'path' ? '' : '#'}${basename != null ? basename : ''}${routes.hostedLoginRedirectUrl}`;
|
|
52
51
|
await actions.loadCustomLoginRoutes();
|
|
53
52
|
const customLoginSearchParam = (_store$auth$customLog = store.auth.customLoginState) == null ? void 0 : _store$auth$customLog.customLoginSearchParams;
|
|
54
53
|
if (customLoginSearchParam) {
|
|
@@ -87,8 +86,9 @@ export default ((store, api, sharedActions) => {
|
|
|
87
86
|
});
|
|
88
87
|
};
|
|
89
88
|
const refreshOrRequestHostedLoginAuthorize = async additionalParams => {
|
|
89
|
+
var _localStorage;
|
|
90
90
|
// when the user pause the step up flow we may still have the key in the local storage in hosted - Remove it
|
|
91
|
-
|
|
91
|
+
(_localStorage = localStorage) == null ? void 0 : _localStorage.removeItem(SHOULD_STEP_UP_KEY);
|
|
92
92
|
const disableSilentRefresh = store.auth.disableSilentRefresh;
|
|
93
93
|
if ((additionalParams == null ? void 0 : additionalParams['prompt']) === 'login') {
|
|
94
94
|
return await requestHostedLoginAuthorize(additionalParams);
|
|
@@ -103,7 +103,7 @@ export default ((store, api, sharedActions) => {
|
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
const refreshOrRequestHostedLoginAuthorizeV2 = async payload => {
|
|
106
|
-
var _additionalParams;
|
|
106
|
+
var _localStorage2, _additionalParams;
|
|
107
107
|
const {
|
|
108
108
|
shouldRedirectToLogin,
|
|
109
109
|
firstTime,
|
|
@@ -113,7 +113,7 @@ export default ((store, api, sharedActions) => {
|
|
|
113
113
|
additionalParams
|
|
114
114
|
} = payload != null ? payload : {};
|
|
115
115
|
// when the user pause the step up flow we may still have the key in the local storage in hosted - Remove it
|
|
116
|
-
|
|
116
|
+
(_localStorage2 = localStorage) == null ? void 0 : _localStorage2.removeItem(SHOULD_STEP_UP_KEY);
|
|
117
117
|
if (firstTime) {
|
|
118
118
|
const urlStrategy = store.root.urlStrategy;
|
|
119
119
|
const activeUri = getUri(urlStrategy);
|
|
@@ -150,11 +150,11 @@ export default ((store, api, sharedActions) => {
|
|
|
150
150
|
const handleHostedLoginCallback = async payload => {
|
|
151
151
|
var _store$auth$customLog2;
|
|
152
152
|
// Hard coded for now
|
|
153
|
-
const code_verifier =
|
|
153
|
+
const code_verifier = localStorage.getItem(HOSTED_LOGIN_VERIFIER_KEY) || 'INVALID-CODE-VERIFIER';
|
|
154
154
|
const routes = store.auth.routes;
|
|
155
155
|
const urlStrategy = store.root.urlStrategy;
|
|
156
156
|
const basename = getBaseNameWithoutSlashSuffix(store);
|
|
157
|
-
let redirectUrl = `${
|
|
157
|
+
let redirectUrl = `${window.location.origin}${urlStrategy === 'path' ? '' : '#'}${basename != null ? basename : ''}${routes.hostedLoginRedirectUrl}`;
|
|
158
158
|
await actions.loadCustomLoginRoutes();
|
|
159
159
|
const customLoginSearchParam = (_store$auth$customLog2 = store.auth.customLoginState) == null ? void 0 : _store$auth$customLog2.customLoginSearchParams;
|
|
160
160
|
if (customLoginSearchParam) {
|
|
@@ -182,8 +182,8 @@ export default ((store, api, sharedActions) => {
|
|
|
182
182
|
console.error('Failed to exchangeOAuthTokens', e);
|
|
183
183
|
} finally {
|
|
184
184
|
const user = store.auth.user;
|
|
185
|
-
const isStepUpFlow =
|
|
186
|
-
|
|
185
|
+
const isStepUpFlow = window.localStorage.getItem(SHOULD_STEP_UP_KEY);
|
|
186
|
+
window.localStorage.removeItem(SHOULD_STEP_UP_KEY);
|
|
187
187
|
|
|
188
188
|
// when the user pause the step up flow we may still have the key in the local storage in hosted. Ignore it.
|
|
189
189
|
if (isStepUpFlow && isSteppedUp(user)) {
|
|
@@ -28,14 +28,14 @@ import { initialState } from '../state';
|
|
|
28
28
|
import { getSearchParam, isEmailPayload, TENANT_ID_PARAM_KEY } from '../helpers';
|
|
29
29
|
import { AuthStrategyEnum, ContextHolder, WebAuthnDeviceType } from '@frontegg/rest-api';
|
|
30
30
|
import hostedLoginAuthorizeActions from './hostedLoginAuthorize.actions';
|
|
31
|
-
import { FronteggNativeModule, isEntitlementsDeeplyEqual
|
|
31
|
+
import { FronteggNativeModule, isEntitlementsDeeplyEqual } from '../../../toolkit';
|
|
32
32
|
import { UserVeirifedOriginTypes } from '../../interfaces';
|
|
33
33
|
import { authStrategyLoginStepMap } from '../consts';
|
|
34
34
|
import { GTMEventAction, reportGTMEvent } from '../../../helpers';
|
|
35
35
|
import { isMfaRequired } from '../../helpers';
|
|
36
36
|
import { MFAStep } from '../../MfaState/interfaces';
|
|
37
37
|
import { SamlVendors } from '../../SSOState/interfaces';
|
|
38
|
-
import {
|
|
38
|
+
import { removeTabTenantFromSessionStorage } from '@frontegg/rest-api';
|
|
39
39
|
export default ((store, api, sharedActions) => {
|
|
40
40
|
const actions = sharedActions;
|
|
41
41
|
const contextHolder = ContextHolder.for(store.root.appName);
|
|
@@ -72,14 +72,14 @@ export default ((store, api, sharedActions) => {
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
|
-
const __shouldNevigateToRegisterQuickLogin =
|
|
75
|
+
const __shouldNevigateToRegisterQuickLogin = user => {
|
|
76
76
|
var _ref;
|
|
77
77
|
const {
|
|
78
78
|
routes,
|
|
79
79
|
loginState
|
|
80
80
|
} = store.auth;
|
|
81
|
-
const quickLoginToRegister = (_ref =
|
|
82
|
-
return quickLoginToRegister &&
|
|
81
|
+
const quickLoginToRegister = (_ref = localStorage.getItem('register-quick-login')) != null ? _ref : loginState.quickLoginToRegister;
|
|
82
|
+
return quickLoginToRegister && localStorage.getItem(`${user.id}-${quickLoginToRegister}`) !== 'true' && !window.location.pathname.endsWith(routes.logoutUrl);
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
/** @private */
|
|
@@ -104,10 +104,10 @@ export default ((store, api, sharedActions) => {
|
|
|
104
104
|
} else {
|
|
105
105
|
var _ref2;
|
|
106
106
|
if (user.id) {
|
|
107
|
-
|
|
107
|
+
localStorage.setItem('userId', user.id);
|
|
108
108
|
}
|
|
109
|
-
const quickLoginToRegister = (_ref2 =
|
|
110
|
-
const shouldNavigateToRegisterQuickLogin =
|
|
109
|
+
const quickLoginToRegister = (_ref2 = localStorage.getItem('register-quick-login')) != null ? _ref2 : loginState.quickLoginToRegister;
|
|
110
|
+
const shouldNavigateToRegisterQuickLogin = __shouldNevigateToRegisterQuickLogin(user);
|
|
111
111
|
const updatedUser = await __handleUnnecessaryEntitlementsUpdate(user);
|
|
112
112
|
actions.afterAuthenticationStateUpdate({
|
|
113
113
|
user: updatedUser,
|
|
@@ -166,7 +166,8 @@ export default ((store, api, sharedActions) => {
|
|
|
166
166
|
|
|
167
167
|
/** @private */
|
|
168
168
|
const __handleRedirectRefreshToken = async shouldNavigateToRegisterQuickLogin => {
|
|
169
|
-
|
|
169
|
+
var _window;
|
|
170
|
+
const url = new URL((_window = window) == null ? void 0 : _window.location.href);
|
|
170
171
|
const {
|
|
171
172
|
routes,
|
|
172
173
|
loginState,
|
|
@@ -179,8 +180,8 @@ export default ((store, api, sharedActions) => {
|
|
|
179
180
|
}
|
|
180
181
|
if (shouldNavigateToRegisterQuickLogin) {
|
|
181
182
|
onRedirectTo(routes.loginUrl);
|
|
182
|
-
} else if (redirectRoutes.some(url => url &&
|
|
183
|
-
if (loginState.isNewUser && routes.signUpSuccessUrl && routes.socialLoginCallbackUrl ===
|
|
183
|
+
} else if (redirectRoutes.some(url => url && window.location.pathname.endsWith(url))) {
|
|
184
|
+
if (loginState.isNewUser && routes.signUpSuccessUrl && routes.socialLoginCallbackUrl === window.location.pathname) {
|
|
184
185
|
onRedirectTo(routes.signUpSuccessUrl, {
|
|
185
186
|
refresh: routes.signUpSuccessUrl.startsWith('http')
|
|
186
187
|
});
|
|
@@ -349,7 +350,7 @@ export default ((store, api, sharedActions) => {
|
|
|
349
350
|
const {
|
|
350
351
|
oidcRedirectUrl
|
|
351
352
|
} = store.auth.routes;
|
|
352
|
-
ssoRedirectUrl += `&redirect_uri=${
|
|
353
|
+
ssoRedirectUrl += `&redirect_uri=${window.location.origin}${oidcRedirectUrl}`;
|
|
353
354
|
}
|
|
354
355
|
if (FronteggNativeModule.isLoginWithSSOAvailable()) {
|
|
355
356
|
FronteggNativeModule.loginWithSSO(email);
|
|
@@ -447,7 +448,7 @@ export default ((store, api, sharedActions) => {
|
|
|
447
448
|
const loginState = store.auth.loginState;
|
|
448
449
|
const isAuthenticated = !!user.accessToken;
|
|
449
450
|
if (user.id) {
|
|
450
|
-
|
|
451
|
+
localStorage.setItem('userId', user.id);
|
|
451
452
|
}
|
|
452
453
|
actions.afterAuthenticationStateUpdate({
|
|
453
454
|
user,
|
|
@@ -495,7 +496,7 @@ export default ((store, api, sharedActions) => {
|
|
|
495
496
|
}
|
|
496
497
|
|
|
497
498
|
// TODO: extract item name to constants
|
|
498
|
-
|
|
499
|
+
localStorage.removeItem('register-quick-login');
|
|
499
500
|
callback == null ? void 0 : callback(true);
|
|
500
501
|
} catch (e) {
|
|
501
502
|
contextHolder.setAccessToken(null);
|
|
@@ -523,7 +524,7 @@ export default ((store, api, sharedActions) => {
|
|
|
523
524
|
/* empty */
|
|
524
525
|
}
|
|
525
526
|
if (contextHolder.isSessionPerTenantEnabled()) {
|
|
526
|
-
|
|
527
|
+
removeTabTenantFromSessionStorage();
|
|
527
528
|
}
|
|
528
529
|
actions.resetAuthState();
|
|
529
530
|
await actions.requestAuthorize(true);
|
|
@@ -537,7 +538,7 @@ export default ((store, api, sharedActions) => {
|
|
|
537
538
|
/* empty */
|
|
538
539
|
}
|
|
539
540
|
if (contextHolder.isSessionPerTenantEnabled()) {
|
|
540
|
-
|
|
541
|
+
removeTabTenantFromSessionStorage();
|
|
541
542
|
}
|
|
542
543
|
setTimeout(() => {
|
|
543
544
|
var _payload$callback;
|
|
@@ -721,7 +722,7 @@ export default ((store, api, sharedActions) => {
|
|
|
721
722
|
reportGTMEvent(GTMEventAction.USER_VERIFIED, userVerifiedPayload);
|
|
722
723
|
}
|
|
723
724
|
if (user.id) {
|
|
724
|
-
|
|
725
|
+
localStorage.setItem('userId', user.id);
|
|
725
726
|
}
|
|
726
727
|
actions.afterAuthenticationStateUpdate({
|
|
727
728
|
user,
|
|
@@ -755,7 +756,7 @@ export default ((store, api, sharedActions) => {
|
|
|
755
756
|
preserveQueryParams: true
|
|
756
757
|
});
|
|
757
758
|
}
|
|
758
|
-
|
|
759
|
+
localStorage.removeItem('register-quick-login');
|
|
759
760
|
callback == null ? void 0 : callback(true);
|
|
760
761
|
}
|
|
761
762
|
} catch (e) {
|
|
@@ -869,7 +870,7 @@ export default ((store, api, sharedActions) => {
|
|
|
869
870
|
});
|
|
870
871
|
} else {
|
|
871
872
|
if (user.id) {
|
|
872
|
-
|
|
873
|
+
localStorage.setItem('userId', user.id);
|
|
873
874
|
}
|
|
874
875
|
actions.afterAuthenticationStateUpdate(_extends({
|
|
875
876
|
user
|
|
@@ -1127,7 +1128,7 @@ export default ((store, api, sharedActions) => {
|
|
|
1127
1128
|
loading: false
|
|
1128
1129
|
});
|
|
1129
1130
|
if (user.id) {
|
|
1130
|
-
|
|
1131
|
+
localStorage.setItem('userId', user.id);
|
|
1131
1132
|
}
|
|
1132
1133
|
};
|
|
1133
1134
|
const resetBreachedPassword = async payload => {
|
|
@@ -1227,10 +1228,10 @@ export default ((store, api, sharedActions) => {
|
|
|
1227
1228
|
} else {
|
|
1228
1229
|
var _ref4;
|
|
1229
1230
|
if (user.id) {
|
|
1230
|
-
|
|
1231
|
+
localStorage.setItem('userId', user.id);
|
|
1231
1232
|
}
|
|
1232
|
-
const quickLoginToRegister = (_ref4 =
|
|
1233
|
-
const shouldNavigateToRegisterQuickLogin =
|
|
1233
|
+
const quickLoginToRegister = (_ref4 = localStorage.getItem('register-quick-login')) != null ? _ref4 : loginState.quickLoginToRegister;
|
|
1234
|
+
const shouldNavigateToRegisterQuickLogin = __shouldNevigateToRegisterQuickLogin(user);
|
|
1234
1235
|
actions.afterAuthenticationStateUpdate({
|
|
1235
1236
|
user: updatedUser,
|
|
1236
1237
|
tenants,
|
|
@@ -2,7 +2,6 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { getMfaStepForEnrolledUsers, getMfaStepForNotEnrolledUsers } from '../helpers';
|
|
3
3
|
import { LoginStep, LoginFlow } from '../interfaces';
|
|
4
4
|
import { MFAStep } from '../../MfaState/interfaces';
|
|
5
|
-
import { LocalStorage } from '../../../toolkit';
|
|
6
5
|
export default ((store, api, sharedActions) => {
|
|
7
6
|
const actions = sharedActions;
|
|
8
7
|
const getMfaRequiredState = async user => {
|
|
@@ -35,7 +34,7 @@ export default ((store, api, sharedActions) => {
|
|
|
35
34
|
step = LoginStep.forceTwoFactor;
|
|
36
35
|
}
|
|
37
36
|
let quickLoginState = {};
|
|
38
|
-
const quickLoginToRegister =
|
|
37
|
+
const quickLoginToRegister = localStorage.getItem('register-quick-login');
|
|
39
38
|
if (quickLoginToRegister) {
|
|
40
39
|
quickLoginState = {
|
|
41
40
|
quickLoginToRegister,
|
|
@@ -3,7 +3,6 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
3
3
|
const _excluded = ["callback"];
|
|
4
4
|
import { LoginFlow, LoginStep } from '../interfaces';
|
|
5
5
|
import { errorHandler } from '../../../helpers';
|
|
6
|
-
import { LocalStorage } from '../../../toolkit';
|
|
7
6
|
export default ((store, api, sharedActions) => {
|
|
8
7
|
const actions = sharedActions;
|
|
9
8
|
|
|
@@ -101,7 +100,7 @@ export default ((store, api, sharedActions) => {
|
|
|
101
100
|
activeTenant
|
|
102
101
|
}, additionalUpdate);
|
|
103
102
|
if (user.id) {
|
|
104
|
-
|
|
103
|
+
localStorage.setItem('userId', user.id);
|
|
105
104
|
}
|
|
106
105
|
setLoadingAction({
|
|
107
106
|
loading: false,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ContextHolder, MFAStrategyEnum } from '@frontegg/rest-api';
|
|
2
2
|
import { MFAStep } from '../MfaState/interfaces';
|
|
3
|
-
import { WindowLocation } from '../../toolkit';
|
|
4
3
|
export const isAbsoluteUrl = path => {
|
|
5
4
|
try {
|
|
6
5
|
new URL(path);
|
|
@@ -10,7 +9,7 @@ export const isAbsoluteUrl = path => {
|
|
|
10
9
|
}
|
|
11
10
|
};
|
|
12
11
|
const isValidRedirectUrl = (redirectUrl, allowedRedirectOrigins) => {
|
|
13
|
-
const currentUrl = new URL(
|
|
12
|
+
const currentUrl = new URL(window.location.href);
|
|
14
13
|
const redirectURL = new URL(redirectUrl);
|
|
15
14
|
const isSameSite = redirectURL.origin === currentUrl.origin;
|
|
16
15
|
const isOriginInWhiteList = allowedRedirectOrigins.includes(redirectURL.origin);
|
|
@@ -22,7 +21,7 @@ export const getRedirectUrl = ({
|
|
|
22
21
|
allowedRedirectOrigins,
|
|
23
22
|
includeQueryParam
|
|
24
23
|
}) => {
|
|
25
|
-
const currentUrl = new URL(
|
|
24
|
+
const currentUrl = new URL(window.location.href);
|
|
26
25
|
let redirectUrl = authenticatedUrl;
|
|
27
26
|
const redirectUrlQueryParam = currentUrl.searchParams.get('redirectUrl');
|
|
28
27
|
if (redirectUrlQueryParam) {
|
|
@@ -36,7 +35,7 @@ export const getRedirectUrl = ({
|
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
} else if (includeQueryParam) {
|
|
39
|
-
redirectUrl +=
|
|
38
|
+
redirectUrl += window.location.search;
|
|
40
39
|
}
|
|
41
40
|
return redirectUrl;
|
|
42
41
|
};
|
|
@@ -67,7 +66,7 @@ export const getPathAndSearchParamsFromUrl = url => {
|
|
|
67
66
|
* @returns the value of the param as string or undefined if it does not exist
|
|
68
67
|
*/
|
|
69
68
|
export const getSearchParam = key => {
|
|
70
|
-
const params = new URLSearchParams(
|
|
69
|
+
const params = new URLSearchParams(window.location.search);
|
|
71
70
|
const param = params.get(key);
|
|
72
71
|
return param != null ? param : undefined;
|
|
73
72
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { deepResetState, errorHandler } from '../../helpers';
|
|
2
2
|
import { initialState } from './state';
|
|
3
3
|
import { SecondaryAuthStrategy } from '@frontegg/rest-api';
|
|
4
|
-
import { LocalStorage } from '../../toolkit';
|
|
5
4
|
export default ((store, api, sharedActions) => {
|
|
6
5
|
const actions = sharedActions;
|
|
7
6
|
const setPasskeysState = payload => {
|
|
@@ -77,8 +76,8 @@ export default ((store, api, sharedActions) => {
|
|
|
77
76
|
policy
|
|
78
77
|
} = publicAuthStrategyPolicy;
|
|
79
78
|
const isPasskeysEnabledByVendor = await getPasskeysVendorPolicy(policy);
|
|
80
|
-
const isLoggedInWithPasskeys =
|
|
81
|
-
const isMarkedDontShowAgainPrompt =
|
|
79
|
+
const isLoggedInWithPasskeys = localStorage.getItem('preferred-login-method') === 'Passkeys';
|
|
80
|
+
const isMarkedDontShowAgainPrompt = localStorage.getItem('dont-show-again-prompt-passkeys') === 'true';
|
|
82
81
|
const [showPasskeys] = await actions.getFeatureFlags(['show-passkeys-new']);
|
|
83
82
|
if (!showPasskeys || !isPasskeysEnabledByVendor || isLoggedInWithPasskeys || isMarkedDontShowAgainPrompt) {
|
|
84
83
|
return false;
|
|
@@ -6,7 +6,6 @@ import { deepResetState, errorHandler } from '../../helpers';
|
|
|
6
6
|
import { initialState } from './state';
|
|
7
7
|
import { AuthenticationTypes, UserVeirifedOriginTypes } from '../interfaces';
|
|
8
8
|
import { GTMEventAction, reportGTMEvent } from '../../helpers/gtm';
|
|
9
|
-
import { LocalStorage } from '../../toolkit';
|
|
10
9
|
export default ((store, api, sharedActions) => {
|
|
11
10
|
const actions = sharedActions;
|
|
12
11
|
|
|
@@ -134,14 +133,14 @@ export default ((store, api, sharedActions) => {
|
|
|
134
133
|
reportGTMEvent(GTMEventAction.USER_VERIFIED, userVerifiedPayload);
|
|
135
134
|
}
|
|
136
135
|
if (userId) {
|
|
137
|
-
|
|
136
|
+
localStorage.setItem('userId', userId);
|
|
138
137
|
}
|
|
139
138
|
actions.setLoginState({
|
|
140
139
|
email,
|
|
141
140
|
isNewUser
|
|
142
141
|
});
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
actions.refreshTokenForSocialLogins();
|
|
143
|
+
localStorage.removeItem('register-quick-login');
|
|
145
144
|
setSocialLoginsState({
|
|
146
145
|
loading: false
|
|
147
146
|
});
|
|
@@ -2,8 +2,6 @@ import { ContextHolder } from '@frontegg/rest-api';
|
|
|
2
2
|
import { getMfaStepForEnrolledUsers } from '../../LoginState/helpers';
|
|
3
3
|
import { MFAStep } from '../../MfaState/interfaces';
|
|
4
4
|
import { SHOULD_STEP_UP_KEY } from '../consts';
|
|
5
|
-
import { LocalStorage } from '../../../toolkit';
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* Error returned from the BE when the user is not enrolled to MFA and logged in with email magic code/link
|
|
9
7
|
*/
|
|
@@ -61,7 +59,7 @@ export default ((store, api, sharedActions) => {
|
|
|
61
59
|
});
|
|
62
60
|
return;
|
|
63
61
|
}
|
|
64
|
-
|
|
62
|
+
window.localStorage.setItem(SHOULD_STEP_UP_KEY, 'true');
|
|
65
63
|
const routes = store.auth.routes;
|
|
66
64
|
ContextHolder.for(store.root.appName).onRedirectTo(routes.logoutUrl, {
|
|
67
65
|
preserveQueryParams: true
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ACR_VALUE, SHOULD_STEP_UP_KEY } from '../consts';
|
|
2
2
|
import { setAfterAuthRedirectUrlForStepUp } from '../helpers';
|
|
3
|
-
import { LocalStorage } from '../../../toolkit';
|
|
4
3
|
export default ((store, api, sharedActions) => {
|
|
5
4
|
const actions = sharedActions;
|
|
6
5
|
|
|
@@ -23,8 +22,8 @@ export default ((store, api, sharedActions) => {
|
|
|
23
22
|
if (alias) {
|
|
24
23
|
params['organization'] = alias;
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
setAfterAuthRedirectUrlForStepUp();
|
|
26
|
+
window.localStorage.setItem(SHOULD_STEP_UP_KEY, 'true');
|
|
28
27
|
await actions.__requestHostedLoginAuthorize(params);
|
|
29
28
|
};
|
|
30
29
|
return {
|
|
@@ -18,7 +18,7 @@ export declare const isSteppedUp: (user?: SteppedUpJWTValues | null, { maxAge }?
|
|
|
18
18
|
/**
|
|
19
19
|
* Set the url and query params in the local storage FRONTEGG_AFTER_AUTH_REDIRECT_URL value
|
|
20
20
|
*/
|
|
21
|
-
export declare function setAfterAuthRedirectUrlForStepUp():
|
|
21
|
+
export declare function setAfterAuthRedirectUrlForStepUp(): void;
|
|
22
22
|
/**
|
|
23
23
|
* Redirects to the step up url with the max age param and set the redirect url in the local storage
|
|
24
24
|
* The redirect url will be used after the step up flow is done
|
|
@@ -26,4 +26,4 @@ export declare function setAfterAuthRedirectUrlForStepUp(): Promise<void>;
|
|
|
26
26
|
* @param onRedirectTo - redirect to function
|
|
27
27
|
* @param maxAge - max age of step up
|
|
28
28
|
*/
|
|
29
|
-
export declare const redirectByStepUpUrl: (stepUpUrl: string, onRedirectTo: (path: string, opts?: RedirectOptions) => void, maxAge?: number) =>
|
|
29
|
+
export declare const redirectByStepUpUrl: (stepUpUrl: string, onRedirectTo: (path: string, opts?: RedirectOptions) => void, maxAge?: number) => void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FRONTEGG_AFTER_AUTH_REDIRECT_URL } from '../../constants';
|
|
2
2
|
import { ACR_VALUE, AMR_MFA_VALUE, AMR_ADDITIONAL_VALUE, STEP_UP_MAX_AGE_PARAM_NAME } from './consts';
|
|
3
|
-
import { WindowLocation, LocalStorage } from '../../toolkit';
|
|
4
3
|
/**
|
|
5
4
|
* @param options.amr
|
|
6
5
|
* @param options.acr
|
|
@@ -31,9 +30,9 @@ export const isSteppedUp = (user, {
|
|
|
31
30
|
/**
|
|
32
31
|
* Set the url and query params in the local storage FRONTEGG_AFTER_AUTH_REDIRECT_URL value
|
|
33
32
|
*/
|
|
34
|
-
export
|
|
35
|
-
const encodedRedirectUrl =
|
|
36
|
-
|
|
33
|
+
export function setAfterAuthRedirectUrlForStepUp() {
|
|
34
|
+
const encodedRedirectUrl = window.location.pathname + window.location.search;
|
|
35
|
+
window.localStorage.setItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL, encodedRedirectUrl);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
/**
|
|
@@ -43,9 +42,9 @@ export async function setAfterAuthRedirectUrlForStepUp() {
|
|
|
43
42
|
* @param onRedirectTo - redirect to function
|
|
44
43
|
* @param maxAge - max age of step up
|
|
45
44
|
*/
|
|
46
|
-
export const redirectByStepUpUrl =
|
|
47
|
-
|
|
48
|
-
const searchParams = new URLSearchParams(
|
|
45
|
+
export const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
|
|
46
|
+
setAfterAuthRedirectUrlForStepUp();
|
|
47
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
49
48
|
if (maxAge) {
|
|
50
49
|
searchParams.set(STEP_UP_MAX_AGE_PARAM_NAME, maxAge.toString());
|
|
51
50
|
}
|
package/helpers/gtm.js
CHANGED
|
@@ -20,8 +20,6 @@ export let GTMEventAction;
|
|
|
20
20
|
* @param payload
|
|
21
21
|
*/
|
|
22
22
|
export function reportGTMEvent(action, payload) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(_window$onFronteggEve = (_window = window).onFronteggEvent) == null ? void 0 : _window$onFronteggEve.call(_window, action, payload);
|
|
26
|
-
}
|
|
23
|
+
var _window$onFronteggEve, _window;
|
|
24
|
+
(_window$onFronteggEve = (_window = window).onFronteggEvent) == null ? void 0 : _window$onFronteggEve.call(_window, action, payload);
|
|
27
25
|
}
|
package/helpers/index.d.ts
CHANGED
package/helpers/index.js
CHANGED
package/helpers/random.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { sha256 } from './sha256';
|
|
2
|
-
import { WindowLocation } from '../toolkit';
|
|
3
2
|
export async function generateCodeChallengePureJs(codeVerifier) {
|
|
4
3
|
// noinspection TypeScriptValidateJSTypes pure sha256 recevie single params alg name
|
|
5
4
|
const digest = sha256.digest(new TextEncoder().encode(codeVerifier));
|
|
@@ -15,7 +14,7 @@ export async function generateCodeChallenge(codeVerifier) {
|
|
|
15
14
|
if ((_window$crypto = window.crypto) != null && (_window$crypto$subtle = _window$crypto.subtle) != null && _window$crypto$subtle.digest) {
|
|
16
15
|
return generateCodeChallengeNative(codeVerifier);
|
|
17
16
|
} else {
|
|
18
|
-
console.warn('Generating CodeChallenge in non-secure domain:',
|
|
17
|
+
console.warn('Generating CodeChallenge in non-secure domain:', window.location.origin);
|
|
19
18
|
return generateCodeChallengePureJs(codeVerifier);
|
|
20
19
|
}
|
|
21
20
|
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license Frontegg v7.
|
|
1
|
+
/** @license Frontegg v7.12.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.
|
|
@@ -18,4 +18,5 @@ export * from './vendor';
|
|
|
18
18
|
export * from './vendor/interfaces';
|
|
19
19
|
export * from './audits';
|
|
20
20
|
export * from './audits/interfaces';
|
|
21
|
+
export * from './helpers/';
|
|
21
22
|
export {};
|
package/interfaces.d.ts
CHANGED
|
@@ -29,6 +29,17 @@ export interface FronteggStore {
|
|
|
29
29
|
store: FronteggState;
|
|
30
30
|
actions: FronteggActions;
|
|
31
31
|
stateActions: FronteggStateActions;
|
|
32
|
+
/**
|
|
33
|
+
* Using redux store subscribe causes unpredictable callback calls: https://redux.js.org/api/store#subscribelistener
|
|
34
|
+
*
|
|
35
|
+
* This function aim to prevent unnecessary update by calling the callback with the updated frontegg state only on state reference change.
|
|
36
|
+
* This function protect from redux unnecessary updates by reference comparison
|
|
37
|
+
* Developed for vanilla js SDK
|
|
38
|
+
*
|
|
39
|
+
* @param callback called with the updated frontegg state for every store refresh
|
|
40
|
+
* @returns redux unsubscribe function
|
|
41
|
+
*/
|
|
42
|
+
subscribeStateChanged: (callback: (state: FronteggState) => void) => () => void;
|
|
32
43
|
}
|
|
33
44
|
export interface RootState {
|
|
34
45
|
appName: string;
|
|
@@ -84,10 +84,7 @@ var _default = (store, api, sharedActions) => {
|
|
|
84
84
|
} = _await$api$auth$activ,
|
|
85
85
|
rest = (0, _objectWithoutPropertiesLoose2.default)(_await$api$auth$activ, _excluded2);
|
|
86
86
|
if (user.redirectLocation) {
|
|
87
|
-
|
|
88
|
-
replace: true,
|
|
89
|
-
refresh: true
|
|
90
|
-
});
|
|
87
|
+
window.location.href = user.redirectLocation;
|
|
91
88
|
return;
|
|
92
89
|
}
|
|
93
90
|
if ((0, _helpers2.isMfaRequired)(user, store.root.appName)) {
|