@frontegg/redux-store 7.75.0 → 7.76.0-alpha.1
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/ForgotPasswordState/actions.d.ts +2 -1
- package/auth/ForgotPasswordState/actions.js +42 -1
- package/auth/ForgotPasswordState/interfaces.d.ts +8 -1
- package/auth/ForgotPasswordState/interfaces.js +3 -0
- package/auth/ForgotPasswordState/state.js +1 -1
- package/auth/LoginState/actions/handleVerifyMFAResponse.actions.js +3 -3
- package/auth/LoginState/actions/index.js +35 -16
- package/auth/LoginState/actions/mfaWithAuthenticator.actions.js +3 -3
- package/auth/LoginState/helpers.d.ts +2 -1
- package/auth/LoginState/helpers.js +4 -1
- package/auth/UsernamesState/actions.d.ts +9 -0
- package/auth/UsernamesState/actions.js +100 -0
- package/auth/UsernamesState/index.d.ts +3 -0
- package/auth/UsernamesState/index.js +3 -0
- package/auth/UsernamesState/interfaces.d.ts +7 -0
- package/auth/UsernamesState/interfaces.js +1 -0
- package/auth/UsernamesState/state.d.ts +4 -0
- package/auth/UsernamesState/state.js +8 -0
- package/auth/index.d.ts +5 -1
- package/auth/index.js +5 -0
- package/auth/interfaces.d.ts +2 -0
- package/index.js +1 -1
- package/mocks/auth-mocks/forgotPasswordActions.mocks.d.ts +1 -0
- package/mocks/auth-mocks/index.js +4 -1
- package/node/auth/ForgotPasswordState/actions.js +42 -1
- package/node/auth/ForgotPasswordState/interfaces.js +3 -0
- package/node/auth/ForgotPasswordState/state.js +1 -1
- package/node/auth/LoginState/actions/handleVerifyMFAResponse.actions.js +3 -3
- package/node/auth/LoginState/actions/index.js +34 -15
- package/node/auth/LoginState/actions/mfaWithAuthenticator.actions.js +3 -3
- package/node/auth/LoginState/helpers.js +7 -2
- package/node/auth/UsernamesState/actions.js +107 -0
- package/node/auth/UsernamesState/index.js +20 -0
- package/node/auth/UsernamesState/interfaces.js +5 -0
- package/node/auth/UsernamesState/state.js +16 -0
- package/node/auth/index.js +18 -2
- package/node/index.js +1 -1
- package/node/mocks/auth-mocks/index.js +4 -1
- package/node/toolkit/FronteggNativeModule.js +3 -3
- package/package.json +2 -2
- package/toolkit/FronteggNativeModule.d.ts +1 -1
- package/toolkit/FronteggNativeModule.js +3 -3
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { IGetUserPasswordConfig } from '@frontegg/rest-api';
|
|
2
2
|
import type { FronteggState, RestApi, SharedActions } from '../../interfaces';
|
|
3
|
-
import type { ForgotPasswordState, IForgotPasswordPayload, IResetPasswordPayload } from './interfaces';
|
|
3
|
+
import type { ForgotPasswordState, IForgotPasswordPayload, IResetPasswordPayload, IDeterminePasswordRecoveryStrategyPayload } from './interfaces';
|
|
4
4
|
declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
|
|
5
5
|
setForgotPasswordState: (payload: Partial<ForgotPasswordState>) => void;
|
|
6
6
|
resetForgotPasswordState: () => void;
|
|
7
7
|
forgotPassword: (payload: IForgotPasswordPayload) => Promise<void>;
|
|
8
8
|
resetPassword: (payload: IResetPasswordPayload) => Promise<void>;
|
|
9
9
|
loadPasswordConfig: (payload?: IGetUserPasswordConfig) => Promise<void>;
|
|
10
|
+
determinePasswordRecoveryStrategy: (payload: IDeterminePasswordRecoveryStrategyPayload) => Promise<void>;
|
|
10
11
|
};
|
|
11
12
|
export default _default;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
const _excluded = ["callback"];
|
|
3
|
+
import { PasswordRecoveryStrategyEnum } from '@frontegg/rest-api';
|
|
3
4
|
import { ForgotPasswordStep } from './interfaces';
|
|
4
5
|
import { initialState } from './state';
|
|
5
6
|
import { errorHandler, deepResetState } from '../../helpers';
|
|
@@ -33,6 +34,45 @@ export default ((store, api, sharedActions) => {
|
|
|
33
34
|
(_payload$callback2 = payload.callback) == null ? void 0 : _payload$callback2.call(payload, false, e);
|
|
34
35
|
}
|
|
35
36
|
};
|
|
37
|
+
const determinePasswordRecoveryStrategy = async payload => {
|
|
38
|
+
setForgotPasswordState({
|
|
39
|
+
loading: true,
|
|
40
|
+
error: undefined,
|
|
41
|
+
identifier: payload.identifier
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
const strategies = await api.auth.getPasswordRecoveryStrategies();
|
|
45
|
+
const isEmailActive = strategies.some(s => s.strategy === PasswordRecoveryStrategyEnum.Email && s.isActive);
|
|
46
|
+
const isSmsActive = strategies.some(s => s.strategy === PasswordRecoveryStrategyEnum.Sms && s.isActive);
|
|
47
|
+
if (isEmailActive && isSmsActive) {
|
|
48
|
+
setForgotPasswordState({
|
|
49
|
+
loading: false,
|
|
50
|
+
step: ForgotPasswordStep.passwordRecoverySelector
|
|
51
|
+
});
|
|
52
|
+
} else if (isEmailActive) {
|
|
53
|
+
await forgotPassword({
|
|
54
|
+
email: payload.identifier,
|
|
55
|
+
recaptchaToken: payload.recaptchaToken
|
|
56
|
+
});
|
|
57
|
+
} else if (isSmsActive) {
|
|
58
|
+
setForgotPasswordState({
|
|
59
|
+
loading: false,
|
|
60
|
+
step: ForgotPasswordStep.resetPasswordViaSms
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
const error = 'No active password recovery methods found.';
|
|
64
|
+
setForgotPasswordState({
|
|
65
|
+
loading: false,
|
|
66
|
+
error
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
setForgotPasswordState({
|
|
71
|
+
loading: false,
|
|
72
|
+
error: errorHandler(e, 'An error occurred while determining recovery strategy')
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
36
76
|
const resetPassword = async payload => {
|
|
37
77
|
const {
|
|
38
78
|
callback
|
|
@@ -79,6 +119,7 @@ export default ((store, api, sharedActions) => {
|
|
|
79
119
|
resetForgotPasswordState,
|
|
80
120
|
forgotPassword,
|
|
81
121
|
resetPassword,
|
|
82
|
-
loadPasswordConfig
|
|
122
|
+
loadPasswordConfig,
|
|
123
|
+
determinePasswordRecoveryStrategy
|
|
83
124
|
};
|
|
84
125
|
});
|
|
@@ -2,6 +2,9 @@ import type { IForgotPassword, IResetPassword } from '@frontegg/rest-api';
|
|
|
2
2
|
import type { WithCallback } from '../../interfaces';
|
|
3
3
|
export declare enum ForgotPasswordStep {
|
|
4
4
|
'forgotPassword' = "forgotPassword",
|
|
5
|
+
'resetPasswordViaSms' = "resetPasswordViaSms",
|
|
6
|
+
'passwordRecoverySelector' = "passwordRecoverySelector",
|
|
7
|
+
'resetPasswordPage' = "resetPasswordPage",
|
|
5
8
|
'success' = "success"
|
|
6
9
|
}
|
|
7
10
|
export interface TestConfig {
|
|
@@ -14,7 +17,7 @@ export interface TestConfig {
|
|
|
14
17
|
export interface ForgotPasswordState {
|
|
15
18
|
step: ForgotPasswordStep;
|
|
16
19
|
passwordConfig: Partial<TestConfig> | null;
|
|
17
|
-
|
|
20
|
+
identifier: string;
|
|
18
21
|
loading: boolean;
|
|
19
22
|
error?: any;
|
|
20
23
|
}
|
|
@@ -24,3 +27,7 @@ export interface IForgotPasswordPayload extends WithCallback<IForgotPassword> {
|
|
|
24
27
|
export interface IResetPasswordPayload extends WithCallback<IResetPassword> {
|
|
25
28
|
recaptchaToken?: string;
|
|
26
29
|
}
|
|
30
|
+
export interface IDeterminePasswordRecoveryStrategyPayload {
|
|
31
|
+
identifier: string;
|
|
32
|
+
recaptchaToken?: string;
|
|
33
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export let ForgotPasswordStep;
|
|
2
2
|
(function (ForgotPasswordStep) {
|
|
3
3
|
ForgotPasswordStep["forgotPassword"] = "forgotPassword";
|
|
4
|
+
ForgotPasswordStep["resetPasswordViaSms"] = "resetPasswordViaSms";
|
|
5
|
+
ForgotPasswordStep["passwordRecoverySelector"] = "passwordRecoverySelector";
|
|
6
|
+
ForgotPasswordStep["resetPasswordPage"] = "resetPasswordPage";
|
|
4
7
|
ForgotPasswordStep["success"] = "success";
|
|
5
8
|
})(ForgotPasswordStep || (ForgotPasswordStep = {}));
|
|
@@ -3,7 +3,7 @@ import { createProxy } from '../../toolkit/proxy';
|
|
|
3
3
|
export const initialState = {
|
|
4
4
|
step: ForgotPasswordStep.forgotPassword,
|
|
5
5
|
loading: false,
|
|
6
|
-
|
|
6
|
+
identifier: '',
|
|
7
7
|
passwordConfig: null
|
|
8
8
|
};
|
|
9
9
|
export default (overrideState => createProxy(initialState, overrideState));
|
|
@@ -29,7 +29,7 @@ export default function (store, api, sharedActions) {
|
|
|
29
29
|
const postHandleVerifyMFAResponseForLogin = async (isAuthenticated, user) => {
|
|
30
30
|
const loginState = store.auth.loginState;
|
|
31
31
|
const mfaStep = store.auth.mfaState.step;
|
|
32
|
-
const [securityCenterLoginFlows
|
|
32
|
+
const [securityCenterLoginFlows] = await actions.getFeatureFlags(['security-center-show-login-flows']);
|
|
33
33
|
if (loginState.flow === LoginFlow.Login) {
|
|
34
34
|
if (securityCenterLoginFlows && loginState.isBreachedPassword && !isAuthenticated) {
|
|
35
35
|
actions.setLoginState({
|
|
@@ -38,7 +38,7 @@ export default function (store, api, sharedActions) {
|
|
|
38
38
|
});
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
if (
|
|
41
|
+
if (isResetPasswordRequired(user, store.root.appName)) {
|
|
42
42
|
actions.setLoginState({
|
|
43
43
|
step: LoginStep.passwordRotationExpired,
|
|
44
44
|
loading: false,
|
|
@@ -47,7 +47,7 @@ export default function (store, api, sharedActions) {
|
|
|
47
47
|
});
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
if (
|
|
50
|
+
if (shouldShowPasswordRotationPromptFunc(user)) {
|
|
51
51
|
actions.setLoginState({
|
|
52
52
|
step: LoginStep.passwordRotationNotification,
|
|
53
53
|
loading: false
|
|
@@ -25,7 +25,7 @@ import mfaWithWebAuthnActions from './mfaWithWebAuthn.actions';
|
|
|
25
25
|
import { LoginFlow, LoginStep } from '../interfaces';
|
|
26
26
|
import { base64urlDecode, deepResetState, delay, errorHandler, errorTraceId, GTMEventAction, publicKeyCredentialToJSON, reportGTMEvent, retryIfNeeded, withRetryConfig } from '../../../helpers';
|
|
27
27
|
import { initialState } from '../state';
|
|
28
|
-
import { getSearchParam, isEmailPayload, shouldShowPasswordRotationPromptFunc, TENANT_ID_PARAM_KEY } from '../helpers';
|
|
28
|
+
import { getSearchParam, isEmailPayload, isUsernamePayload, shouldShowPasswordRotationPromptFunc, TENANT_ID_PARAM_KEY } from '../helpers';
|
|
29
29
|
import { AuthStrategyEnum, ContextHolder, removeTabTenantFromSessionStorage, WebAuthnDeviceType } from '@frontegg/rest-api';
|
|
30
30
|
import hostedLoginAuthorizeActions from './hostedLoginAuthorize.actions';
|
|
31
31
|
import { FronteggNativeModule, isEntitlementsDeeplyEqual } from '../../../toolkit';
|
|
@@ -347,6 +347,7 @@ export default ((store, api, sharedActions) => {
|
|
|
347
347
|
const preLogin = async payload => {
|
|
348
348
|
const {
|
|
349
349
|
email,
|
|
350
|
+
username,
|
|
350
351
|
recaptchaToken,
|
|
351
352
|
invitationToken,
|
|
352
353
|
callback
|
|
@@ -357,10 +358,13 @@ export default ((store, api, sharedActions) => {
|
|
|
357
358
|
try {
|
|
358
359
|
const onRedirectTo = store.auth.onRedirectTo;
|
|
359
360
|
const tenantId = getSearchParam(TENANT_ID_PARAM_KEY);
|
|
360
|
-
const preLoginResult = await api.auth.preLoginV2({
|
|
361
|
-
email
|
|
361
|
+
const preLoginResult = await api.auth.preLoginV2(_extends({}, email ? {
|
|
362
|
+
email
|
|
363
|
+
} : {}, username ? {
|
|
364
|
+
username
|
|
365
|
+
} : {}, {
|
|
362
366
|
tenantId
|
|
363
|
-
});
|
|
367
|
+
}));
|
|
364
368
|
const {
|
|
365
369
|
address,
|
|
366
370
|
idpType
|
|
@@ -374,7 +378,8 @@ export default ((store, api, sharedActions) => {
|
|
|
374
378
|
ssoRedirectUrl += `&redirect_uri=${window.location.origin}${oidcRedirectUrl}`;
|
|
375
379
|
}
|
|
376
380
|
if (FronteggNativeModule.isLoginWithSSOAvailable()) {
|
|
377
|
-
|
|
381
|
+
var _ref4;
|
|
382
|
+
FronteggNativeModule.loginWithSSO((_ref4 = email != null ? email : username) != null ? _ref4 : '');
|
|
378
383
|
setLoginState({
|
|
379
384
|
loading: false
|
|
380
385
|
});
|
|
@@ -392,16 +397,18 @@ export default ((store, api, sharedActions) => {
|
|
|
392
397
|
}, 2000);
|
|
393
398
|
}
|
|
394
399
|
} else {
|
|
400
|
+
var _ref5;
|
|
395
401
|
await ssoPreloginFailed({
|
|
396
|
-
email,
|
|
402
|
+
email: (_ref5 = email != null ? email : username) != null ? _ref5 : '',
|
|
397
403
|
recaptchaToken,
|
|
398
404
|
callback,
|
|
399
405
|
invitationToken
|
|
400
406
|
});
|
|
401
407
|
}
|
|
402
408
|
} catch (e) {
|
|
409
|
+
var _ref6;
|
|
403
410
|
await ssoPreloginFailed({
|
|
404
|
-
email,
|
|
411
|
+
email: (_ref6 = email != null ? email : username) != null ? _ref6 : '',
|
|
405
412
|
recaptchaToken,
|
|
406
413
|
callback,
|
|
407
414
|
invitationToken,
|
|
@@ -437,6 +444,7 @@ export default ((store, api, sharedActions) => {
|
|
|
437
444
|
const login = async payload => {
|
|
438
445
|
const {
|
|
439
446
|
email,
|
|
447
|
+
username,
|
|
440
448
|
password,
|
|
441
449
|
recaptchaToken,
|
|
442
450
|
invitationToken,
|
|
@@ -450,12 +458,15 @@ export default ((store, api, sharedActions) => {
|
|
|
450
458
|
user,
|
|
451
459
|
tenants = [],
|
|
452
460
|
activeTenant
|
|
453
|
-
} = await api.auth.loginv2({
|
|
454
|
-
email
|
|
461
|
+
} = await api.auth.loginv2(_extends({}, email ? {
|
|
462
|
+
email
|
|
463
|
+
} : {}, username ? {
|
|
464
|
+
username
|
|
465
|
+
} : {}, {
|
|
455
466
|
password,
|
|
456
467
|
recaptchaToken,
|
|
457
468
|
invitationToken
|
|
458
|
-
});
|
|
469
|
+
}));
|
|
459
470
|
const {
|
|
460
471
|
onRedirectTo,
|
|
461
472
|
routes
|
|
@@ -467,8 +478,8 @@ export default ((store, api, sharedActions) => {
|
|
|
467
478
|
preserveQueryParams: true
|
|
468
479
|
});
|
|
469
480
|
} else {
|
|
470
|
-
const [securityCenterLoginFlows
|
|
471
|
-
if (
|
|
481
|
+
const [securityCenterLoginFlows] = await actions.getFeatureFlags(['security-center-show-login-flows']);
|
|
482
|
+
if (isResetPasswordRequired(user, store.root.appName)) {
|
|
472
483
|
setLoginState({
|
|
473
484
|
step: LoginStep.passwordRotationExpired,
|
|
474
485
|
loading: false,
|
|
@@ -509,7 +520,7 @@ export default ((store, api, sharedActions) => {
|
|
|
509
520
|
} else {
|
|
510
521
|
if (isAuthenticated) {
|
|
511
522
|
const shouldShowPasswordRotationPrompt = shouldShowPasswordRotationPromptFunc(user);
|
|
512
|
-
if (
|
|
523
|
+
if (shouldShowPasswordRotationPrompt) {
|
|
513
524
|
setLoginState({
|
|
514
525
|
step: LoginStep.passwordRotationNotification,
|
|
515
526
|
loading: false
|
|
@@ -695,6 +706,7 @@ export default ((store, api, sharedActions) => {
|
|
|
695
706
|
} = _payload,
|
|
696
707
|
payload = _objectWithoutPropertiesLoose(_payload, _excluded5);
|
|
697
708
|
try {
|
|
709
|
+
var _username;
|
|
698
710
|
setLoginState({
|
|
699
711
|
loading: true
|
|
700
712
|
});
|
|
@@ -702,9 +714,16 @@ export default ((store, api, sharedActions) => {
|
|
|
702
714
|
if (isEmailPayload(payload)) {
|
|
703
715
|
email = payload.email;
|
|
704
716
|
}
|
|
717
|
+
let username;
|
|
718
|
+
if (isUsernamePayload(payload)) {
|
|
719
|
+
username = payload.username;
|
|
720
|
+
}
|
|
705
721
|
// TODO: [Typescript 4.8] fix @frontegg/rest-api return value
|
|
706
722
|
// @ts-ignore
|
|
707
|
-
const preloginRes = await api.auth.passwordlessPreLogin(payload
|
|
723
|
+
const preloginRes = await api.auth.passwordlessPreLogin(_extends({}, payload, {
|
|
724
|
+
email,
|
|
725
|
+
username: (_username = username) != null ? _username : ''
|
|
726
|
+
}));
|
|
708
727
|
// @ts-ignore
|
|
709
728
|
const step = authStrategyLoginStepMap[payload.type];
|
|
710
729
|
setLoginState({
|
|
@@ -1296,11 +1315,11 @@ export default ((store, api, sharedActions) => {
|
|
|
1296
1315
|
preserveQueryParams: true
|
|
1297
1316
|
});
|
|
1298
1317
|
} else {
|
|
1299
|
-
var
|
|
1318
|
+
var _ref7;
|
|
1300
1319
|
if (user.id) {
|
|
1301
1320
|
localStorage.setItem('userId', user.id);
|
|
1302
1321
|
}
|
|
1303
|
-
const quickLoginToRegister = (
|
|
1322
|
+
const quickLoginToRegister = (_ref7 = localStorage.getItem('register-quick-login')) != null ? _ref7 : loginState.quickLoginToRegister;
|
|
1304
1323
|
const shouldNavigateToRegisterQuickLogin = __shouldNavigateToRegisterQuickLogin(user);
|
|
1305
1324
|
actions.afterAuthenticationStateUpdate({
|
|
1306
1325
|
user: updatedUser,
|
|
@@ -42,7 +42,7 @@ export default ((store, api, sharedActions) => {
|
|
|
42
42
|
async function __postLoginMfaAuthenticator(isAuthenticated, user, callback) {
|
|
43
43
|
const loginState = store.auth.loginState;
|
|
44
44
|
if (loginState.flow !== LoginFlow.Login) return;
|
|
45
|
-
const [securityCenterLoginFlows
|
|
45
|
+
const [securityCenterLoginFlows] = await actions.getFeatureFlags(['security-center-show-login-flows']);
|
|
46
46
|
if (securityCenterLoginFlows && loginState.isBreachedPassword && !isAuthenticated) {
|
|
47
47
|
actions.setLoginState({
|
|
48
48
|
step: LoginStep.breachedPassword,
|
|
@@ -51,7 +51,7 @@ export default ((store, api, sharedActions) => {
|
|
|
51
51
|
callback == null ? void 0 : callback(true);
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
if (
|
|
54
|
+
if (isResetPasswordRequired(user, store.root.appName)) {
|
|
55
55
|
actions.setLoginState({
|
|
56
56
|
step: LoginStep.passwordRotationExpired,
|
|
57
57
|
loading: false,
|
|
@@ -62,7 +62,7 @@ export default ((store, api, sharedActions) => {
|
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
const shouldShowPasswordRotationPrompt = shouldShowPasswordRotationPromptFunc(user);
|
|
65
|
-
if (
|
|
65
|
+
if (shouldShowPasswordRotationPrompt) {
|
|
66
66
|
actions.setLoginState({
|
|
67
67
|
step: LoginStep.passwordRotationNotification,
|
|
68
68
|
loading: false
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IEmailPasswordlessPreLogin, ILoginResponse, IPasswordlessPreLogin, MFAStrategyEnum, UserMFADevicesResponse } from '@frontegg/rest-api';
|
|
1
|
+
import { IEmailPasswordlessPreLogin, ILoginResponse, IPasswordlessPreLogin, IUsernamePasswordlessPreLogin, MFAStrategyEnum, UserMFADevicesResponse } from '@frontegg/rest-api';
|
|
2
2
|
import { FronteggState } from '../../interfaces';
|
|
3
3
|
import { User } from '../interfaces';
|
|
4
4
|
import { MFAStep } from '../MfaState/interfaces';
|
|
@@ -29,5 +29,6 @@ export declare const getMfaStepForEnrolledUsers: (mfaDevices: UserMFADevicesResp
|
|
|
29
29
|
export declare const getMfaStepForNotEnrolledUsers: (mfaStrategies: MFAStrategyEnum[]) => MFAStep.verify | MFAStep.authenticatorApp | MFAStep.smsSetPhoneNumber | MFAStep.emailVerifyCode;
|
|
30
30
|
export declare const isOauthCallbackRoute: (activeUri: string) => boolean;
|
|
31
31
|
export declare function isEmailPayload(payload: IPasswordlessPreLogin): payload is IEmailPasswordlessPreLogin;
|
|
32
|
+
export declare function isUsernamePayload(payload: IPasswordlessPreLogin): payload is IUsernamePasswordlessPreLogin;
|
|
32
33
|
export declare const getBaseNameWithoutSlashSuffix: (state: FronteggState) => string | null;
|
|
33
34
|
export declare const shouldShowPasswordRotationPromptFunc: (user: ILoginResponse | User) => boolean;
|
|
@@ -124,7 +124,10 @@ export const isOauthCallbackRoute = activeUri => {
|
|
|
124
124
|
return activeUri === '/oauth/callback';
|
|
125
125
|
};
|
|
126
126
|
export function isEmailPayload(payload) {
|
|
127
|
-
return 'email' in payload;
|
|
127
|
+
return 'email' in payload && typeof payload['email'] === 'string';
|
|
128
|
+
}
|
|
129
|
+
export function isUsernamePayload(payload) {
|
|
130
|
+
return 'username' in payload && typeof payload['username'] === 'string';
|
|
128
131
|
}
|
|
129
132
|
export const getBaseNameWithoutSlashSuffix = state => {
|
|
130
133
|
const basename = ContextHolder.for(state.root.appName).getBasename();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICreateUsername } from '@frontegg/rest-api/usernames/interfaces';
|
|
2
|
+
import { FronteggState, RestApi, SharedActions, WithCallback } from '../../interfaces';
|
|
3
|
+
declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
|
|
4
|
+
resetUsernamesState: () => void;
|
|
5
|
+
loadUserOwnUsername: () => Promise<void>;
|
|
6
|
+
saveUserUsername: (payload: WithCallback<ICreateUsername, void>) => Promise<void>;
|
|
7
|
+
deleteUserUsername: (username: string) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { deepResetState, errorHandler } from '../../helpers';
|
|
2
|
+
import { initialState } from './state';
|
|
3
|
+
export default ((store, api, sharedActions) => {
|
|
4
|
+
const setUsernamesState = state => {
|
|
5
|
+
Object.assign(store.auth.usernamesState, state);
|
|
6
|
+
};
|
|
7
|
+
const resetUsernamesState = () => {
|
|
8
|
+
deepResetState(store, ['auth', 'usernamesState'], initialState);
|
|
9
|
+
};
|
|
10
|
+
const loadUserOwnUsername = async () => {
|
|
11
|
+
setUsernamesState({
|
|
12
|
+
loading: true
|
|
13
|
+
});
|
|
14
|
+
try {
|
|
15
|
+
const response = await api.usernames.getUserOwnUsername();
|
|
16
|
+
setUsernamesState({
|
|
17
|
+
username: response == null ? void 0 : response.username,
|
|
18
|
+
loading: false,
|
|
19
|
+
fetching: false
|
|
20
|
+
});
|
|
21
|
+
} catch (e) {
|
|
22
|
+
setUsernamesState({
|
|
23
|
+
error: errorHandler(e),
|
|
24
|
+
fetching: false
|
|
25
|
+
});
|
|
26
|
+
} finally {
|
|
27
|
+
setUsernamesState({
|
|
28
|
+
loading: false,
|
|
29
|
+
fetching: false
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const saveUserUsername = async payload => {
|
|
34
|
+
setUsernamesState({
|
|
35
|
+
loading: true
|
|
36
|
+
});
|
|
37
|
+
try {
|
|
38
|
+
if (store.auth.usernamesState.username === payload.username) {
|
|
39
|
+
var _payload$callback;
|
|
40
|
+
(_payload$callback = payload.callback) == null ? void 0 : _payload$callback.call(payload);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (store.auth.usernamesState.username && store.auth.usernamesState.username !== payload.username) {
|
|
44
|
+
await deleteUserUsername(store.auth.usernamesState.username);
|
|
45
|
+
if (!payload.username) {
|
|
46
|
+
var _payload$callback2;
|
|
47
|
+
setUsernamesState({
|
|
48
|
+
username: undefined,
|
|
49
|
+
loading: false
|
|
50
|
+
});
|
|
51
|
+
(_payload$callback2 = payload.callback) == null ? void 0 : _payload$callback2.call(payload);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!!payload.username) {
|
|
56
|
+
var _payload$callback3;
|
|
57
|
+
await api.usernames.createUsername(payload);
|
|
58
|
+
setUsernamesState({
|
|
59
|
+
username: payload.username,
|
|
60
|
+
loading: false
|
|
61
|
+
});
|
|
62
|
+
(_payload$callback3 = payload.callback) == null ? void 0 : _payload$callback3.call(payload);
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
setUsernamesState({
|
|
66
|
+
error: errorHandler(e)
|
|
67
|
+
});
|
|
68
|
+
} finally {
|
|
69
|
+
setUsernamesState({
|
|
70
|
+
loading: false
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const deleteUserUsername = async username => {
|
|
75
|
+
setUsernamesState({
|
|
76
|
+
loading: true
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
await api.usernames.deleteUsername(username);
|
|
80
|
+
setUsernamesState({
|
|
81
|
+
username: undefined,
|
|
82
|
+
loading: false
|
|
83
|
+
});
|
|
84
|
+
} catch (e) {
|
|
85
|
+
setUsernamesState({
|
|
86
|
+
error: errorHandler(e)
|
|
87
|
+
});
|
|
88
|
+
} finally {
|
|
89
|
+
setUsernamesState({
|
|
90
|
+
loading: false
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
resetUsernamesState,
|
|
96
|
+
loadUserOwnUsername,
|
|
97
|
+
saveUserUsername,
|
|
98
|
+
deleteUserUsername
|
|
99
|
+
};
|
|
100
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/auth/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { buildSSOActions } from './SSOState';
|
|
|
33
33
|
import { buildStepUpActions } from './StepUpState';
|
|
34
34
|
import { buildTeamActions } from './TeamState';
|
|
35
35
|
import { buildTenantsActions } from './TenantsState';
|
|
36
|
+
import { buildUsernamesActions } from './UsernamesState';
|
|
36
37
|
import { buildUserEmailPolicyActions } from './UsersEmailsPolicyState';
|
|
37
38
|
import { buildEntitlementsActions } from './Entitlements';
|
|
38
39
|
export * from './AcceptInvitationState/interfaces';
|
|
@@ -69,6 +70,7 @@ export * from './SSOState/interfaces';
|
|
|
69
70
|
export * from './StepUpState/interfaces';
|
|
70
71
|
export * from './TeamState/interfaces';
|
|
71
72
|
export * from './TenantsState/interfaces';
|
|
73
|
+
export * from './UsernamesState/interfaces';
|
|
72
74
|
export * from './UsersEmailsPolicyState/interfaces';
|
|
73
75
|
export * from './interfaces';
|
|
74
76
|
export declare const createAuthState: (_overrideState?: DeepPartial<AuthState>) => AuthState;
|
|
@@ -107,6 +109,7 @@ export type SSOActions = ReturnType<typeof buildSSOActions>;
|
|
|
107
109
|
export type StepUpActions = ReturnType<typeof buildStepUpActions>;
|
|
108
110
|
export type TeamActions = ReturnType<typeof buildTeamActions>;
|
|
109
111
|
export type TenantsActions = ReturnType<typeof buildTenantsActions>;
|
|
112
|
+
export type UsernamesActions = ReturnType<typeof buildUsernamesActions>;
|
|
110
113
|
export type UsersEmailPolicyActions = ReturnType<typeof buildUserEmailPolicyActions>;
|
|
111
114
|
export type AuthStateActions = {
|
|
112
115
|
acceptInvitationActions: AcceptInvitationActions;
|
|
@@ -143,6 +146,7 @@ export type AuthStateActions = {
|
|
|
143
146
|
stepUpActions: StepUpActions;
|
|
144
147
|
teamActions: TeamActions;
|
|
145
148
|
tenantsActions: TenantsActions;
|
|
149
|
+
usernamesActions: UsernamesActions;
|
|
146
150
|
usersEmailsPolicyActions: UsersEmailPolicyActions;
|
|
147
151
|
};
|
|
148
152
|
export type AuthActions = {
|
|
@@ -152,4 +156,4 @@ export type AuthActions = {
|
|
|
152
156
|
setErrorByRequestName: (payload: SingleErrorByRequestDataPayload) => void;
|
|
153
157
|
resetAuthState: (state?: Partial<AuthState>) => void;
|
|
154
158
|
setUser: (user: User | null) => void;
|
|
155
|
-
} & AcceptInvitationActions & AccountSettingsActions & UnlockAccountActions & ActivateAccountActions & ApiTokensActions & ApplicationsActions & CustomLoginActions & EntitlementsActions & ForgotPasswordActions & PasswordRotationActions & GroupsActions & GroupsDialogsActions & ImpersonateActions & LoginActions & MfaActions & AllAccountsActions & AllAccountsDialogActions & PasskeysActions & ProfileActions & ProvisioningActions & ResetPhoneNumberActions & RolesActions & RestrictionsActions & SecurityCenterActions & SecurityPolicyActions & SessionsPolicyActions & SessionsActions & SignUpActions & SmsActions & SocialLoginActions & SSOActions & StepUpActions & TeamActions & TenantsActions & UsersEmailPolicyActions;
|
|
159
|
+
} & AcceptInvitationActions & AccountSettingsActions & UnlockAccountActions & ActivateAccountActions & ApiTokensActions & ApplicationsActions & CustomLoginActions & EntitlementsActions & ForgotPasswordActions & PasswordRotationActions & GroupsActions & GroupsDialogsActions & ImpersonateActions & LoginActions & MfaActions & AllAccountsActions & AllAccountsDialogActions & PasskeysActions & ProfileActions & ProvisioningActions & ResetPhoneNumberActions & RolesActions & RestrictionsActions & SecurityCenterActions & SecurityPolicyActions & SessionsPolicyActions & SessionsActions & SignUpActions & SmsActions & SocialLoginActions & SSOActions & StepUpActions & TeamActions & TenantsActions & UsernamesActions & UsersEmailPolicyActions;
|
package/auth/index.js
CHANGED
|
@@ -34,6 +34,7 @@ import { buildSSOActions, createSSOState } from './SSOState';
|
|
|
34
34
|
import { buildStepUpActions, createStepUpState } from './StepUpState';
|
|
35
35
|
import { buildTeamActions, createTeamState } from './TeamState';
|
|
36
36
|
import { buildTenantsActions, createTenantsState } from './TenantsState';
|
|
37
|
+
import { buildUsernamesActions, createUsernamesState } from './UsernamesState';
|
|
37
38
|
import { buildUserEmailPolicyActions, createUserEmailPolicyState } from './UsersEmailsPolicyState';
|
|
38
39
|
import { defaultFronteggRoutes } from './LoginState/consts';
|
|
39
40
|
import { deepResetState, isProxy } from '../helpers';
|
|
@@ -73,6 +74,7 @@ export * from './SSOState/interfaces';
|
|
|
73
74
|
export * from './StepUpState/interfaces';
|
|
74
75
|
export * from './TeamState/interfaces';
|
|
75
76
|
export * from './TenantsState/interfaces';
|
|
77
|
+
export * from './UsernamesState/interfaces';
|
|
76
78
|
export * from './UsersEmailsPolicyState/interfaces';
|
|
77
79
|
export * from './interfaces';
|
|
78
80
|
export const createAuthState = _overrideState => {
|
|
@@ -129,6 +131,7 @@ export const createAuthState = _overrideState => {
|
|
|
129
131
|
stepUpState: createStepUpState(overrideState == null ? void 0 : overrideState.stepUpState),
|
|
130
132
|
teamState: createTeamState(overrideState == null ? void 0 : overrideState.teamState),
|
|
131
133
|
tenantsState: createTenantsState(overrideState == null ? void 0 : overrideState.tenantsState),
|
|
134
|
+
usernamesState: createUsernamesState(overrideState == null ? void 0 : overrideState.usernamesState),
|
|
132
135
|
userEmailPolicyState: createUserEmailPolicyState(overrideState == null ? void 0 : overrideState.userEmailPolicyState)
|
|
133
136
|
}));
|
|
134
137
|
};
|
|
@@ -196,6 +199,7 @@ export const buildAuthActions = (store, api, actions, snapshotAuthState) => {
|
|
|
196
199
|
const stepUpActions = buildStepUpActions(store, api, actions);
|
|
197
200
|
const teamActions = buildTeamActions(store, api, actions);
|
|
198
201
|
const tenantsActions = buildTenantsActions(store, api, actions);
|
|
202
|
+
const usernamesActions = buildUsernamesActions(store, api, actions);
|
|
199
203
|
const usersEmailsPolicyActions = buildUserEmailPolicyActions(store, api, actions);
|
|
200
204
|
const stateActions = {
|
|
201
205
|
acceptInvitationActions,
|
|
@@ -232,6 +236,7 @@ export const buildAuthActions = (store, api, actions, snapshotAuthState) => {
|
|
|
232
236
|
stepUpActions,
|
|
233
237
|
teamActions,
|
|
234
238
|
tenantsActions,
|
|
239
|
+
usernamesActions,
|
|
235
240
|
usersEmailsPolicyActions
|
|
236
241
|
};
|
|
237
242
|
return [_extends({
|
package/auth/interfaces.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ import type { IAllAccountsDialogsState, IAllAccountsState } from './MSP/interfac
|
|
|
31
31
|
import { ApplicationsState } from './ApplicationsState/interfaces';
|
|
32
32
|
import { UnlockAccountState } from './UnlockAccountState/interfaces';
|
|
33
33
|
import { PasswordRotationState } from '../toolkit';
|
|
34
|
+
import { UsernamesState } from './UsernamesState/interfaces';
|
|
34
35
|
import { UserEmailPolicyState } from './UsersEmailsPolicyState/interfaces';
|
|
35
36
|
export declare enum REQUEST_NAME {
|
|
36
37
|
LOAD_FEATURE_FLAGS = "LOAD_FEATURE_FLAGS,",
|
|
@@ -108,6 +109,7 @@ export interface AuthState extends Routes, PluginOptions {
|
|
|
108
109
|
teamState: TeamState;
|
|
109
110
|
tenantsState: TenantsState;
|
|
110
111
|
applicationsState: ApplicationsState;
|
|
112
|
+
usernamesState: UsernamesState;
|
|
111
113
|
userEmailPolicyState: UserEmailPolicyState;
|
|
112
114
|
}
|
|
113
115
|
interface Actor {
|
package/index.js
CHANGED
|
@@ -6,5 +6,6 @@ declare const _default: (store: FronteggState, api: RestApi, actions: SharedActi
|
|
|
6
6
|
forgotPassword: (payload: import("../..").IForgotPasswordPayload) => Promise<void>;
|
|
7
7
|
resetPassword: (payload: import("../..").IResetPasswordPayload) => Promise<void>;
|
|
8
8
|
loadPasswordConfig: (payload?: IGetUserPasswordConfig) => Promise<void>;
|
|
9
|
+
determinePasswordRecoveryStrategy: (payload: import("../..").IDeterminePasswordRecoveryStrategyPayload) => Promise<void>;
|
|
9
10
|
};
|
|
10
11
|
export default _default;
|
|
@@ -39,6 +39,7 @@ import buildTenantsActions from './tenantsActions.mocks';
|
|
|
39
39
|
import buildUnlockAccountActions from './unlockAccountActions.mocks';
|
|
40
40
|
import buildUserEmailPolicyActions from './usersEmailsPolicyActions.mocks';
|
|
41
41
|
import { deepResetState, isProxy } from '../../helpers';
|
|
42
|
+
import { buildUsernamesActions } from '../../auth/UsernamesState';
|
|
42
43
|
export const buildAuthActions = (store, api, actions, snapshotAuthState) => {
|
|
43
44
|
const acceptInvitationActions = buildAcceptInvitationActions(store, api, actions);
|
|
44
45
|
const accountSettingsActions = buildAccountSettingsActions(store, api, actions);
|
|
@@ -74,6 +75,7 @@ export const buildAuthActions = (store, api, actions, snapshotAuthState) => {
|
|
|
74
75
|
const stepUpActions = buildStepUpActions(store, api, actions);
|
|
75
76
|
const teamActions = buildTeamActions(store, api, actions);
|
|
76
77
|
const tenantsActions = buildTenantsActions(store, api, actions);
|
|
78
|
+
const usernamesActions = buildUsernamesActions(store, api, actions);
|
|
77
79
|
const usersEmailsPolicyActions = buildUserEmailPolicyActions(store, api, actions);
|
|
78
80
|
const authStateActions = {
|
|
79
81
|
acceptInvitationActions,
|
|
@@ -110,6 +112,7 @@ export const buildAuthActions = (store, api, actions, snapshotAuthState) => {
|
|
|
110
112
|
stepUpActions,
|
|
111
113
|
teamActions,
|
|
112
114
|
tenantsActions,
|
|
115
|
+
usernamesActions,
|
|
113
116
|
usersEmailsPolicyActions
|
|
114
117
|
};
|
|
115
118
|
const setAuthState = state => {
|
|
@@ -148,7 +151,7 @@ export const buildAuthActions = (store, api, actions, snapshotAuthState) => {
|
|
|
148
151
|
setErrorByRequestName,
|
|
149
152
|
resetAuthState,
|
|
150
153
|
setUser
|
|
151
|
-
}, acceptInvitationActions, accountSettingsActions, activateAccountActions, unlockAccountActions, allAccountsActions, allAccountsDialogActions, apiTokensActions, applicationsActions, customLoginActions, entitlementsActions, forgotPasswordActions, passwordRotationActions, groupsActions, groupsDialogsActions, impersonateActions, loginActions, mfaActions, passkeysActions, profileActions, provisioningActions, resetPhoneNumberActions, restrictionsActions, rolesActions, securityCenterActions, securityPolicyActions, sessionsActions, sessionsPolicyActions, signUpActions, smsActions, socialLoginActions, ssoActions, stepUpActions, teamActions, tenantsActions, usersEmailsPolicyActions);
|
|
154
|
+
}, acceptInvitationActions, accountSettingsActions, activateAccountActions, unlockAccountActions, allAccountsActions, allAccountsDialogActions, apiTokensActions, applicationsActions, customLoginActions, entitlementsActions, forgotPasswordActions, passwordRotationActions, groupsActions, groupsDialogsActions, impersonateActions, loginActions, mfaActions, passkeysActions, profileActions, provisioningActions, resetPhoneNumberActions, restrictionsActions, rolesActions, securityCenterActions, securityPolicyActions, sessionsActions, sessionsPolicyActions, signUpActions, smsActions, socialLoginActions, ssoActions, stepUpActions, teamActions, tenantsActions, usernamesActions, usersEmailsPolicyActions);
|
|
152
155
|
return {
|
|
153
156
|
authActions,
|
|
154
157
|
authStateActions
|