@frontegg/redux-store 6.155.0-alpha.3 → 6.155.0-alpha.5

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.
@@ -3,13 +3,15 @@ import { User } from '../../interfaces';
3
3
  interface AfterAuthNavigationUtilOptions {
4
4
  customLoginAuthenticatedUrl?: string;
5
5
  forceStepUpUrl?: string;
6
+ shouldStepUpDuringLogin?: boolean;
6
7
  }
7
8
  /**
8
9
  * Utility to share after auth navigation flow between login and step up
9
10
  * @param resetStateAction reset state action
10
11
  * @param customLoginAuthenticatedUrl custom login authenticated url if exists
12
+ * @param shouldStepUpDuringLogin true when it's login after step up flow
11
13
  */
12
- export declare function afterAuthNavigationUtil(resetStateAction: () => Action, { customLoginAuthenticatedUrl, forceStepUpUrl }?: AfterAuthNavigationUtilOptions): Generator<import("redux-saga/effects").CallEffect<true> | import("redux-saga/effects").CallEffect<string>, void, string>;
14
+ export declare function afterAuthNavigationUtil(resetStateAction: () => Action, { customLoginAuthenticatedUrl, forceStepUpUrl, shouldStepUpDuringLogin }?: AfterAuthNavigationUtilOptions): Generator<import("redux-saga/effects").CallEffect<true> | import("redux-saga/effects").CallEffect<string>, void, string | undefined>;
13
15
  /**
14
16
  * After auth navigation for login flow
15
17
  * Handling also step up scenario when user silently logout to continue to step up
@@ -2,7 +2,7 @@ import { ContextHolder } from '@frontegg/rest-api';
2
2
  import { delay, put, select, call } from 'redux-saga/effects';
3
3
  import { loadCustomLoginRoutes } from '../../CustomLoginState/saga';
4
4
  import { actions } from '../../reducer';
5
- import { getPathAndSearchParamsFromUrl, getRedirectUrl } from '../utils';
5
+ import { getPathAndSearchParamsFromUrl, getRedirectUrl, isAbsoluteUrl } from '../utils';
6
6
  import { FRONTEGG_AFTER_AUTH_REDIRECT_URL } from '../../../constants';
7
7
  import { isSteppedUp } from '../../StepUpState';
8
8
  import { SHOULD_STEP_UP_KEY } from '../../StepUpState/consts';
@@ -43,20 +43,32 @@ function* getUrlForAfterAuthNavigation(customLoginAuthenticatedUrl) {
43
43
  * Utility to share after auth navigation flow between login and step up
44
44
  * @param resetStateAction reset state action
45
45
  * @param customLoginAuthenticatedUrl custom login authenticated url if exists
46
+ * @param shouldStepUpDuringLogin true when it's login after step up flow
46
47
  */
47
48
  export function* afterAuthNavigationUtil(resetStateAction, {
48
49
  customLoginAuthenticatedUrl,
49
- forceStepUpUrl
50
+ forceStepUpUrl,
51
+ shouldStepUpDuringLogin
50
52
  } = {}) {
51
53
  const onRedirectTo = ContextHolder.onRedirectTo;
52
- let redirectUrl;
54
+ let redirectUrl = undefined;
53
55
  if (forceStepUpUrl) {
54
56
  // scenario to get to here: invalid max age, try to step up -> logout, login with magic code/link -> redirect to step up page for email code as the second factor
55
57
  // we don't want to remove the FRONTEGG_AFTER_AUTH_REDIRECT_URL when we are in the step up flow
56
58
  redirectUrl = forceStepUpUrl;
57
59
  } else {
58
60
  var _window;
59
- redirectUrl = yield call(getUrlForAfterAuthNavigation, customLoginAuthenticatedUrl);
61
+ if (shouldStepUpDuringLogin) {
62
+ // getUrlForAfterAuthNavigation give priority to the redirectUrl
63
+ // avoiding use of getUrlForAfterAuthNavigation because we don't want to use the redirectUrl for magic link for example
64
+ const localStorageRedirectUrl = window.localStorage.getItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL);
65
+ if (localStorageRedirectUrl && !isAbsoluteUrl(localStorageRedirectUrl)) {
66
+ redirectUrl = localStorageRedirectUrl;
67
+ }
68
+ }
69
+ if (!redirectUrl) {
70
+ redirectUrl = yield call(getUrlForAfterAuthNavigation, customLoginAuthenticatedUrl);
71
+ }
60
72
  (_window = window) == null ? void 0 : _window.localStorage.removeItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL);
61
73
  }
62
74
  yield delay(200);
@@ -103,7 +115,8 @@ export function* afterAuthNavigation() {
103
115
  });
104
116
  }
105
117
  yield call(afterAuthNavigationUtil, actions.resetLoginState, {
106
- customLoginAuthenticatedUrl: customLoginURL
118
+ customLoginAuthenticatedUrl: customLoginURL,
119
+ shouldStepUpDuringLogin: !!shouldStepUp
107
120
  });
108
121
  }
109
122
 
@@ -1,5 +1,6 @@
1
1
  import { IEmailPasswordlessPreLogin, ILoginResponse, IPasswordlessPreLogin, MFAStrategyEnum, UserMFADevicesResponse } from '@frontegg/rest-api';
2
2
  import { MFAStep } from '../MfaState/interfaces';
3
+ export declare const isAbsoluteUrl: (path: string) => boolean;
3
4
  export declare const getRedirectUrl: ({ authenticatedUrl, enforceRedirectToSameSite, allowedRedirectOrigins, includeQueryParam, }: {
4
5
  authenticatedUrl: string;
5
6
  enforceRedirectToSameSite: boolean;
@@ -1,6 +1,6 @@
1
1
  import { ContextHolder, MFAStrategyEnum } from '@frontegg/rest-api';
2
2
  import { MFAStep } from '../MfaState/interfaces';
3
- const isAbsoluteUrl = path => {
3
+ export const isAbsoluteUrl = path => {
4
4
  try {
5
5
  new URL(path);
6
6
  return true;
@@ -59,12 +59,13 @@ function* handleError(error) {
59
59
  }));
60
60
  return;
61
61
  }
62
- yield put(actions.logout());
63
62
  window.localStorage.setItem(SHOULD_STEP_UP_KEY, 'true');
64
63
  const {
65
64
  routes
66
65
  } = yield select(state => state.auth);
67
- ContextHolder.onRedirectTo(routes.loginUrl);
66
+ ContextHolder.onRedirectTo(routes.logoutUrl, {
67
+ preserveQueryParams: true
68
+ });
68
69
  }
69
70
 
70
71
  /**
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.155.0-alpha.3
1
+ /** @license Frontegg v6.155.0-alpha.5
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.
@@ -50,20 +50,32 @@ function* getUrlForAfterAuthNavigation(customLoginAuthenticatedUrl) {
50
50
  * Utility to share after auth navigation flow between login and step up
51
51
  * @param resetStateAction reset state action
52
52
  * @param customLoginAuthenticatedUrl custom login authenticated url if exists
53
+ * @param shouldStepUpDuringLogin true when it's login after step up flow
53
54
  */
54
55
  function* afterAuthNavigationUtil(resetStateAction, {
55
56
  customLoginAuthenticatedUrl,
56
- forceStepUpUrl
57
+ forceStepUpUrl,
58
+ shouldStepUpDuringLogin
57
59
  } = {}) {
58
60
  const onRedirectTo = _restApi.ContextHolder.onRedirectTo;
59
- let redirectUrl;
61
+ let redirectUrl = undefined;
60
62
  if (forceStepUpUrl) {
61
63
  // scenario to get to here: invalid max age, try to step up -> logout, login with magic code/link -> redirect to step up page for email code as the second factor
62
64
  // we don't want to remove the FRONTEGG_AFTER_AUTH_REDIRECT_URL when we are in the step up flow
63
65
  redirectUrl = forceStepUpUrl;
64
66
  } else {
65
67
  var _window;
66
- redirectUrl = yield (0, _effects.call)(getUrlForAfterAuthNavigation, customLoginAuthenticatedUrl);
68
+ if (shouldStepUpDuringLogin) {
69
+ // getUrlForAfterAuthNavigation give priority to the redirectUrl
70
+ // avoiding use of getUrlForAfterAuthNavigation because we don't want to use the redirectUrl for magic link for example
71
+ const localStorageRedirectUrl = window.localStorage.getItem(_constants.FRONTEGG_AFTER_AUTH_REDIRECT_URL);
72
+ if (localStorageRedirectUrl && !(0, _utils.isAbsoluteUrl)(localStorageRedirectUrl)) {
73
+ redirectUrl = localStorageRedirectUrl;
74
+ }
75
+ }
76
+ if (!redirectUrl) {
77
+ redirectUrl = yield (0, _effects.call)(getUrlForAfterAuthNavigation, customLoginAuthenticatedUrl);
78
+ }
67
79
  (_window = window) == null ? void 0 : _window.localStorage.removeItem(_constants.FRONTEGG_AFTER_AUTH_REDIRECT_URL);
68
80
  }
69
81
  yield (0, _effects.delay)(200);
@@ -110,7 +122,8 @@ function* afterAuthNavigation() {
110
122
  });
111
123
  }
112
124
  yield (0, _effects.call)(afterAuthNavigationUtil, _reducer.actions.resetLoginState, {
113
- customLoginAuthenticatedUrl: customLoginURL
125
+ customLoginAuthenticatedUrl: customLoginURL,
126
+ shouldStepUpDuringLogin: !!shouldStepUp
114
127
  });
115
128
  }
116
129
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getSearchParamsFromUrl = exports.getSearchParam = exports.getRedirectUrl = exports.getPathAndSearchParamsFromUrl = exports.getNumberOfMfaDevices = exports.getMfaStepForNotEnrolledUsers = exports.getMfaStepForEnrolledUsers = exports.TENANT_ID_PARAM_KEY = void 0;
6
+ exports.isAbsoluteUrl = exports.getSearchParamsFromUrl = exports.getSearchParam = exports.getRedirectUrl = exports.getPathAndSearchParamsFromUrl = exports.getNumberOfMfaDevices = exports.getMfaStepForNotEnrolledUsers = exports.getMfaStepForEnrolledUsers = exports.TENANT_ID_PARAM_KEY = void 0;
7
7
  exports.isEmailPayload = isEmailPayload;
8
8
  exports.isOauthCallbackRoute = exports.isMfaRequired = void 0;
9
9
  var _restApi = require("@frontegg/rest-api");
@@ -16,6 +16,7 @@ const isAbsoluteUrl = path => {
16
16
  return false;
17
17
  }
18
18
  };
19
+ exports.isAbsoluteUrl = isAbsoluteUrl;
19
20
  const isValidRedirectUrl = (redirectUrl, allowedRedirectOrigins) => {
20
21
  const currentUrl = new URL(window.location.href);
21
22
  const redirectURL = new URL(redirectUrl);
@@ -64,12 +64,13 @@ function* handleError(error) {
64
64
  }));
65
65
  return;
66
66
  }
67
- yield (0, _effects.put)(_reducer.actions.logout());
68
67
  window.localStorage.setItem(_consts.SHOULD_STEP_UP_KEY, 'true');
69
68
  const {
70
69
  routes
71
70
  } = yield (0, _effects.select)(state => state.auth);
72
- _restApi.ContextHolder.onRedirectTo(routes.loginUrl);
71
+ _restApi.ContextHolder.onRedirectTo(routes.logoutUrl, {
72
+ preserveQueryParams: true
73
+ });
73
74
  }
74
75
 
75
76
  /**
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.155.0-alpha.3
1
+ /** @license Frontegg v6.155.0-alpha.5
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "6.155.0-alpha.3",
3
+ "version": "6.155.0-alpha.5",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",