@frontegg/redux-store 6.5.1 → 6.6.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/LoginState/saga.js +26 -12
- package/index.js +1 -1
- package/node/auth/LoginState/saga.js +26 -12
- package/node/index.js +1 -1
- package/node/toolkit/index.js +5 -3
- package/package.json +1 -1
- package/toolkit/index.d.ts +2 -1
- package/toolkit/index.js +5 -3
package/auth/LoginState/saga.js
CHANGED
|
@@ -375,11 +375,13 @@ function* requestHostedLoginAuthorize({
|
|
|
375
375
|
const {
|
|
376
376
|
routes,
|
|
377
377
|
context,
|
|
378
|
-
onRedirectTo
|
|
378
|
+
onRedirectTo,
|
|
379
|
+
urlStrategy
|
|
379
380
|
} = yield select(state => ({
|
|
380
381
|
routes: state.auth.routes,
|
|
381
382
|
onRedirectTo: state.auth.onRedirectTo,
|
|
382
|
-
context: state.root.context
|
|
383
|
+
context: state.root.context,
|
|
384
|
+
urlStrategy: state.root.urlStrategy
|
|
383
385
|
})); // Generate the relevant params for the redirect
|
|
384
386
|
|
|
385
387
|
const nonce = createRandomString();
|
|
@@ -387,7 +389,7 @@ function* requestHostedLoginAuthorize({
|
|
|
387
389
|
const code_challenge = yield call(generateCodeChallenge, code_verifier); // We are saving the verifier in session storage to be able to validate the response
|
|
388
390
|
|
|
389
391
|
localStorage.setItem(HOSTED_LOGIN_VERIFIER_KEY, code_verifier);
|
|
390
|
-
const redirectUrl = `${window.location.origin}${routes.hostedLoginRedirectUrl}`;
|
|
392
|
+
const redirectUrl = `${window.location.origin}${urlStrategy === 'path' ? '' : '#'}${routes.hostedLoginRedirectUrl}`;
|
|
391
393
|
const baseUrl = fetch.getBaseUrl(context, '/oauth/authorize'); // Hard coded for now
|
|
392
394
|
|
|
393
395
|
const oauthUrl = `${baseUrl}/oauth/authorize`;
|
|
@@ -414,22 +416,34 @@ function* handleHostedLoginCallback({
|
|
|
414
416
|
}) {
|
|
415
417
|
// Hard coded for now
|
|
416
418
|
const code_verifier = localStorage.getItem(HOSTED_LOGIN_VERIFIER_KEY) || 'INVALID-CODE-VERIFIER';
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
+
const {
|
|
420
|
+
routes,
|
|
421
|
+
urlStrategy
|
|
422
|
+
} = yield select(state => ({
|
|
423
|
+
routes: state.auth.routes,
|
|
424
|
+
urlStrategy: state.root.urlStrategy
|
|
425
|
+
}));
|
|
426
|
+
const redirectUrl = `${window.location.origin}${urlStrategy === 'path' ? '' : '#'}${routes.hostedLoginRedirectUrl}`;
|
|
419
427
|
const body = {
|
|
420
428
|
code: payload.code,
|
|
421
429
|
redirect_uri: redirectUrl,
|
|
422
430
|
code_verifier,
|
|
423
431
|
grant_type: 'authorization_code'
|
|
424
432
|
};
|
|
425
|
-
const user = yield call(api.auth.exchangeOAuthTokens, body); // TODO: Validate nonce and aud
|
|
426
433
|
|
|
427
|
-
|
|
428
|
-
user,
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
434
|
+
try {
|
|
435
|
+
const user = yield call(api.auth.exchangeOAuthTokens, body); // TODO: Validate nonce and aud
|
|
436
|
+
|
|
437
|
+
yield put(actions.setState({
|
|
438
|
+
user,
|
|
439
|
+
isAuthenticated: true
|
|
440
|
+
}));
|
|
441
|
+
yield put(actions.loadTenants());
|
|
442
|
+
} catch (e) {
|
|
443
|
+
console.error('Failed to exchangeOAuthTokens', e);
|
|
444
|
+
} finally {
|
|
445
|
+
yield afterAuthNavigation();
|
|
446
|
+
}
|
|
433
447
|
}
|
|
434
448
|
|
|
435
449
|
function* changePhoneNumberWithVerification(_ref2) {
|
package/index.js
CHANGED
|
@@ -430,11 +430,13 @@ function* requestHostedLoginAuthorize({
|
|
|
430
430
|
const {
|
|
431
431
|
routes,
|
|
432
432
|
context,
|
|
433
|
-
onRedirectTo
|
|
433
|
+
onRedirectTo,
|
|
434
|
+
urlStrategy
|
|
434
435
|
} = yield (0, _effects.select)(state => ({
|
|
435
436
|
routes: state.auth.routes,
|
|
436
437
|
onRedirectTo: state.auth.onRedirectTo,
|
|
437
|
-
context: state.root.context
|
|
438
|
+
context: state.root.context,
|
|
439
|
+
urlStrategy: state.root.urlStrategy
|
|
438
440
|
})); // Generate the relevant params for the redirect
|
|
439
441
|
|
|
440
442
|
const nonce = (0, _helpers.createRandomString)();
|
|
@@ -442,7 +444,7 @@ function* requestHostedLoginAuthorize({
|
|
|
442
444
|
const code_challenge = yield (0, _effects.call)(_helpers.generateCodeChallenge, code_verifier); // We are saving the verifier in session storage to be able to validate the response
|
|
443
445
|
|
|
444
446
|
localStorage.setItem(_constants.HOSTED_LOGIN_VERIFIER_KEY, code_verifier);
|
|
445
|
-
const redirectUrl = `${window.location.origin}${routes.hostedLoginRedirectUrl}`;
|
|
447
|
+
const redirectUrl = `${window.location.origin}${urlStrategy === 'path' ? '' : '#'}${routes.hostedLoginRedirectUrl}`;
|
|
446
448
|
|
|
447
449
|
const baseUrl = _restApi.fetch.getBaseUrl(context, '/oauth/authorize'); // Hard coded for now
|
|
448
450
|
|
|
@@ -469,22 +471,34 @@ function* handleHostedLoginCallback({
|
|
|
469
471
|
}) {
|
|
470
472
|
// Hard coded for now
|
|
471
473
|
const code_verifier = localStorage.getItem(_constants.HOSTED_LOGIN_VERIFIER_KEY) || 'INVALID-CODE-VERIFIER';
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
+
const {
|
|
475
|
+
routes,
|
|
476
|
+
urlStrategy
|
|
477
|
+
} = yield (0, _effects.select)(state => ({
|
|
478
|
+
routes: state.auth.routes,
|
|
479
|
+
urlStrategy: state.root.urlStrategy
|
|
480
|
+
}));
|
|
481
|
+
const redirectUrl = `${window.location.origin}${urlStrategy === 'path' ? '' : '#'}${routes.hostedLoginRedirectUrl}`;
|
|
474
482
|
const body = {
|
|
475
483
|
code: payload.code,
|
|
476
484
|
redirect_uri: redirectUrl,
|
|
477
485
|
code_verifier,
|
|
478
486
|
grant_type: 'authorization_code'
|
|
479
487
|
};
|
|
480
|
-
const user = yield (0, _effects.call)(_restApi.api.auth.exchangeOAuthTokens, body); // TODO: Validate nonce and aud
|
|
481
488
|
|
|
482
|
-
|
|
483
|
-
user,
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
489
|
+
try {
|
|
490
|
+
const user = yield (0, _effects.call)(_restApi.api.auth.exchangeOAuthTokens, body); // TODO: Validate nonce and aud
|
|
491
|
+
|
|
492
|
+
yield (0, _effects.put)(_reducer.actions.setState({
|
|
493
|
+
user,
|
|
494
|
+
isAuthenticated: true
|
|
495
|
+
}));
|
|
496
|
+
yield (0, _effects.put)(_reducer.actions.loadTenants());
|
|
497
|
+
} catch (e) {
|
|
498
|
+
console.error('Failed to exchangeOAuthTokens', e);
|
|
499
|
+
} finally {
|
|
500
|
+
yield afterAuthNavigation();
|
|
501
|
+
}
|
|
488
502
|
}
|
|
489
503
|
|
|
490
504
|
function* changePhoneNumberWithVerification(_ref2) {
|
package/node/index.js
CHANGED
package/node/toolkit/index.js
CHANGED
|
@@ -72,7 +72,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
72
72
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
73
73
|
|
|
74
74
|
const initialState = {
|
|
75
|
-
context: undefined
|
|
75
|
+
context: undefined,
|
|
76
|
+
urlStrategy: 'path'
|
|
76
77
|
};
|
|
77
78
|
const {
|
|
78
79
|
reducer: rootReducer
|
|
@@ -97,7 +98,7 @@ const {
|
|
|
97
98
|
}
|
|
98
99
|
});
|
|
99
100
|
|
|
100
|
-
const createFronteggStore = (rootInitialState, storeHolder, previewMode = false, authInitialState, overrideInitialState, builderMode = false) => {
|
|
101
|
+
const createFronteggStore = (rootInitialState, storeHolder, previewMode = false, authInitialState, overrideInitialState, builderMode = false, urlStrategy = 'path') => {
|
|
101
102
|
const isSSR = typeof window === 'undefined';
|
|
102
103
|
let holder = storeHolder;
|
|
103
104
|
|
|
@@ -126,7 +127,8 @@ const createFronteggStore = (rootInitialState, storeHolder, previewMode = false,
|
|
|
126
127
|
middleware,
|
|
127
128
|
preloadedState: {
|
|
128
129
|
root: (0, _extends2.default)({}, rootInitialState, {
|
|
129
|
-
previewMode
|
|
130
|
+
previewMode,
|
|
131
|
+
urlStrategy: urlStrategy
|
|
130
132
|
}),
|
|
131
133
|
[_auth.default.storeName]: (0, _extends2.default)({}, _auth.default.initialState, authInitialState, (_overrideInitialState = overrideInitialState == null ? void 0 : overrideInitialState.auth) != null ? _overrideInitialState : {}, {
|
|
132
134
|
routes: (0, _extends2.default)({}, _auth.default.initialState.routes, (_authInitialState$rou = authInitialState == null ? void 0 : authInitialState.routes) != null ? _authInitialState$rou : {}, (_overrideInitialState2 = overrideInitialState == null ? void 0 : (_overrideInitialState3 = overrideInitialState.auth) == null ? void 0 : _overrideInitialState3.routes) != null ? _overrideInitialState2 : {})
|
package/package.json
CHANGED
package/toolkit/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { bindActionCreators } from '@reduxjs/toolkit';
|
|
|
12
12
|
export type { CaseReducerActions, SliceCaseReducers } from '@reduxjs/toolkit';
|
|
13
13
|
export interface RootState {
|
|
14
14
|
context?: ContextOptions;
|
|
15
|
+
urlStrategy: 'hash' | 'path';
|
|
15
16
|
}
|
|
16
17
|
export declare const createFronteggStore: (rootInitialState: InitialState, storeHolder?: any, previewMode?: boolean, authInitialState?: (Partial<Pick<AuthState, "user" | "error" | "onRedirectTo" | "isAuthenticated" | "isLoading" | "keepSessionAlive" | "isSSOAuth" | "ssoACS" | "loginState" | "activateState" | "acceptInvitationState" | "forgotPasswordState" | "resetPhoneNumberState" | "ssoState" | "profileState" | "mfaState" | "teamState" | "socialLoginState" | "signUpState" | "apiTokensState" | "securityPolicyState" | "accountSettingsState" | "tenantsState" | "rolesState" | "sessionsState" | "hostedLoginBox" | "sessionsPolicyState" | "header" | "loaderComponent">> & {
|
|
17
18
|
routes?: Partial<AuthPageRoutes> | undefined;
|
|
@@ -21,4 +22,4 @@ export declare const createFronteggStore: (rootInitialState: InitialState, store
|
|
|
21
22
|
};
|
|
22
23
|
auditLogs: Partial<AuditsState>;
|
|
23
24
|
audits: Partial<OldAuditsState>;
|
|
24
|
-
}> | undefined, builderMode?: boolean) => EnhancedStore;
|
|
25
|
+
}> | undefined, builderMode?: boolean, urlStrategy?: 'hash' | 'path') => EnhancedStore;
|
package/toolkit/index.js
CHANGED
|
@@ -14,7 +14,8 @@ export * from './redux';
|
|
|
14
14
|
export * from './redux-saga';
|
|
15
15
|
export { bindActionCreators } from '@reduxjs/toolkit';
|
|
16
16
|
const initialState = {
|
|
17
|
-
context: undefined
|
|
17
|
+
context: undefined,
|
|
18
|
+
urlStrategy: 'path'
|
|
18
19
|
};
|
|
19
20
|
const {
|
|
20
21
|
reducer: rootReducer
|
|
@@ -37,7 +38,7 @@ const {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
});
|
|
40
|
-
export const createFronteggStore = (rootInitialState, storeHolder, previewMode = false, authInitialState, overrideInitialState, builderMode = false) => {
|
|
41
|
+
export const createFronteggStore = (rootInitialState, storeHolder, previewMode = false, authInitialState, overrideInitialState, builderMode = false, urlStrategy = 'path') => {
|
|
41
42
|
const isSSR = typeof window === 'undefined';
|
|
42
43
|
let holder = storeHolder;
|
|
43
44
|
|
|
@@ -66,7 +67,8 @@ export const createFronteggStore = (rootInitialState, storeHolder, previewMode =
|
|
|
66
67
|
middleware,
|
|
67
68
|
preloadedState: {
|
|
68
69
|
root: _extends({}, rootInitialState, {
|
|
69
|
-
previewMode
|
|
70
|
+
previewMode,
|
|
71
|
+
urlStrategy: urlStrategy
|
|
70
72
|
}),
|
|
71
73
|
[authStore.storeName]: _extends({}, authStore.initialState, authInitialState, (_overrideInitialState = overrideInitialState == null ? void 0 : overrideInitialState.auth) != null ? _overrideInitialState : {}, {
|
|
72
74
|
routes: _extends({}, authStore.initialState.routes, (_authInitialState$rou = authInitialState == null ? void 0 : authInitialState.routes) != null ? _authInitialState$rou : {}, (_overrideInitialState2 = overrideInitialState == null ? void 0 : (_overrideInitialState3 = overrideInitialState.auth) == null ? void 0 : _overrideInitialState3.routes) != null ? _overrideInitialState2 : {})
|