@frontegg/redux-store 7.65.0 → 7.67.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.
@@ -278,6 +278,7 @@ export default ((store, api, sharedActions) => {
278
278
  calls.push(actions.loadSocialLoginsConfigurationV2(withRetryConfig()));
279
279
  calls.push(actions.loadAllowSignUps(getRetryWithBlockingCallbackPayload(REQUEST_NAME.LOAD_ALLOW_SIGNUPS)));
280
280
  calls.push(actions.loadPublicAuthStrategiesPolicy(getRetryWithBlockingCallbackPayload(REQUEST_NAME.LOAD_PUBLIC_AUTH_STRATEGIES_POLICY)));
281
+ calls.push(actions.loadSignUpStrategies());
281
282
  calls.push(__loadSSOPublicConfigurationFunction(getRetryWithBlockingCallbackPayload(REQUEST_NAME.LOAD_SSO_PUBLIC_CONFIGURATION)));
282
283
  calls.push(actions.loadVendorPublicInfo(withRetryConfig()));
283
284
  calls.push(__refreshMetadata(withRetryConfig()));
@@ -301,6 +302,7 @@ export default ((store, api, sharedActions) => {
301
302
  calls.push(actions.loadSocialLoginsConfigurationV2(withRetryConfig()));
302
303
  calls.push(actions.loadAllowSignUps(getRetryWithBlockingCallbackPayload(REQUEST_NAME.LOAD_ALLOW_SIGNUPS)));
303
304
  calls.push(__loadSSOPublicConfigurationFunction(getRetryWithBlockingCallbackPayload(REQUEST_NAME.LOAD_SSO_PUBLIC_CONFIGURATION)));
305
+ calls.push(actions.loadSignUpStrategies());
304
306
  calls.push(actions.loadVendorPublicInfo(withRetryConfig()));
305
307
  calls.push(__refreshMetadata());
306
308
  calls.push(__isMFARequiredSSR(payload));
@@ -6,6 +6,8 @@ declare const _default: (store: FronteggState, api: RestApi, sharedActions: Shar
6
6
  resetSignUpState: () => void;
7
7
  resetSignUpStateSoft: () => void;
8
8
  signUpUser: (_payload: ISignUpUserPayload) => Promise<void>;
9
+ signUpUserWithPhoneNumber: (_payload: ISignUpUserPayload) => Promise<void>;
9
10
  loadAllowSignUps: (payload?: WithCallback<WithRetryConfig<{}>, IVendorConfig>) => Promise<void>;
11
+ loadSignUpStrategies: () => Promise<void>;
10
12
  };
11
13
  export default _default;
@@ -1,14 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["events", "url"];
3
+ const _excluded = ["events", "url"],
4
+ _excluded2 = ["events", "url"];
4
5
  import { SignUpStage } from './interfaces';
5
6
  import { deepResetState, errorHandler, retryIfNeeded } from '../../helpers';
6
7
  import { initialState } from './state';
7
- import { ContextHolder } from '@frontegg/rest-api';
8
- import { extractPhoneNumber, isMfaRequired } from '../helpers';
8
+ import { AuthStrategyEnum, ContextHolder } from '@frontegg/rest-api';
9
+ import { prepareIdentifiersForSignup, isMfaRequired } from '../helpers';
9
10
  import { AuthenticationTypes } from '../interfaces';
10
11
  import { GTMEventAction, reportGTMEvent } from '../../helpers/gtm';
11
12
  import { DEFAULT_RETRY_CONFIG } from '../../constants';
13
+ import { LoginStep } from '../../toolkit';
12
14
  export default ((store, api, sharedActions) => {
13
15
  const actions = sharedActions;
14
16
  const contextHolder = ContextHolder.for(store.root.appName);
@@ -29,15 +31,101 @@ export default ((store, api, sharedActions) => {
29
31
  allowNotVerifiedUsersLogin
30
32
  });
31
33
  };
32
- const signUpUser = async _payload => {
34
+ const reportSignupCompletion = (payload, userId, tenantId, activationToken, events, authenticationType = AuthenticationTypes.PASSWORD) => {
35
+ var _events$signUpComplet;
36
+ const {
37
+ email,
38
+ name,
39
+ companyName,
40
+ phoneNumber,
41
+ url
42
+ } = payload;
43
+ const signUpCompletePayload = {
44
+ email,
45
+ name,
46
+ companyName,
47
+ url,
48
+ phoneNumber: phoneNumber || undefined,
49
+ authenticationType,
50
+ id: userId,
51
+ tenantId,
52
+ createdAt: new Date(),
53
+ activationToken
54
+ };
55
+ events == null ? void 0 : (_events$signUpComplet = events.signUpComplete) == null ? void 0 : _events$signUpComplet.call(events, signUpCompletePayload);
56
+ reportGTMEvent(GTMEventAction.SIGNUP_COMPLETED, signUpCompletePayload);
57
+ };
58
+ const signUpUserWithPhoneNumber = async _payload => {
33
59
  const {
34
- events,
35
- url
60
+ events
36
61
  } = _payload,
37
62
  payload = _objectWithoutPropertiesLoose(_payload, _excluded);
38
63
  setSignUpState({
39
64
  loading: true
40
65
  });
66
+ if (!payload.phoneNumber) {
67
+ throw new Error('Phone number is required for phone number signup');
68
+ }
69
+ try {
70
+ var _store$auth$securityP, _grecaptcha, _grecaptcha$execute;
71
+ const {
72
+ routes,
73
+ onRedirectTo
74
+ } = store.auth;
75
+ const {
76
+ tenantId,
77
+ userId,
78
+ activationToken
79
+ } = await api.auth.signUpUserWithPhoneNumber(prepareIdentifiersForSignup(payload));
80
+ if (!payload.invitationToken) {
81
+ reportSignupCompletion(payload, userId, tenantId, activationToken, events, AuthenticationTypes.PHONE_NUMBER);
82
+ }
83
+ const {
84
+ enabled: captchaEnabled,
85
+ siteKey
86
+ } = (_store$auth$securityP = store.auth.securityPolicyState.captchaPolicy.policy) != null ? _store$auth$securityP : {};
87
+ const recaptchaToken = captchaEnabled && siteKey ? await ((_grecaptcha = window.grecaptcha) == null ? void 0 : (_grecaptcha$execute = _grecaptcha.execute) == null ? void 0 : _grecaptcha$execute.call(_grecaptcha, {
88
+ action: 'login'
89
+ })) : '';
90
+ actions.passwordlessPreLogin({
91
+ recaptchaToken,
92
+ phoneNumber: payload.phoneNumber,
93
+ type: AuthStrategyEnum.SmsCode,
94
+ callback: (success, error) => {
95
+ if (!success && error) {
96
+ throw error;
97
+ }
98
+ onRedirectTo(routes.loginUrl);
99
+ actions.setLoginState({
100
+ step: LoginStep.loginWithSmsOtc,
101
+ phoneNumber: payload.phoneNumber
102
+ });
103
+ }
104
+ });
105
+ } catch (e) {
106
+ contextHolder.setAccessToken(null);
107
+ contextHolder.setUser(null);
108
+ setSignUpState({
109
+ error: errorHandler(e)
110
+ });
111
+ } finally {
112
+ setSignUpState({
113
+ loading: false
114
+ });
115
+ }
116
+ };
117
+ const signUpUser = async _payload => {
118
+ const {
119
+ events
120
+ } = _payload,
121
+ payload = _objectWithoutPropertiesLoose(_payload, _excluded2);
122
+ setSignUpState({
123
+ loading: true
124
+ });
125
+ const phoneNumberStrategy = store.auth.signUpState.strategies.phoneNumber;
126
+ if (phoneNumberStrategy != null && phoneNumberStrategy.required && phoneNumberStrategy != null && phoneNumberStrategy.enabled && payload.phoneNumber) {
127
+ return signUpUserWithPhoneNumber(_payload);
128
+ }
41
129
  try {
42
130
  const {
43
131
  routes,
@@ -51,32 +139,9 @@ export default ((store, api, sharedActions) => {
51
139
  tenants = [],
52
140
  activeTenant,
53
141
  activationToken
54
- } = await api.auth.signUpUser(
55
- //Currently we are not supporting phone number in signup in the backend
56
- //Remove this line when we will support it (also make sure when field is optional no empty string is sent)
57
- extractPhoneNumber(payload));
142
+ } = await api.auth.signUpUser(prepareIdentifiersForSignup(payload));
58
143
  if (!payload.invitationToken) {
59
- var _events$signUpComplet;
60
- const {
61
- email,
62
- name,
63
- companyName,
64
- phoneNumber
65
- } = payload;
66
- const signUpCompletePayload = {
67
- email,
68
- name,
69
- companyName,
70
- url,
71
- phoneNumber: phoneNumber || undefined,
72
- authenticationType: AuthenticationTypes.PASSWORD,
73
- id: userId,
74
- tenantId,
75
- createdAt: new Date(),
76
- activationToken
77
- };
78
- events == null ? void 0 : (_events$signUpComplet = events.signUpComplete) == null ? void 0 : _events$signUpComplet.call(events, signUpCompletePayload);
79
- reportGTMEvent(GTMEventAction.SIGNUP_COMPLETED, signUpCompletePayload);
144
+ reportSignupCompletion(payload, userId, tenantId, activationToken, events);
80
145
  }
81
146
  if (!shouldActivate && user && isMfaRequired(user, store.root.appName)) {
82
147
  const mfaRequiredState = await actions.getMfaRequiredState(user, DEFAULT_RETRY_CONFIG, true, payload.email);
@@ -155,11 +220,31 @@ export default ((store, api, sharedActions) => {
155
220
  payload == null ? void 0 : (_payload$callback2 = payload.callback) == null ? void 0 : _payload$callback2.call(payload, null, e);
156
221
  }
157
222
  };
223
+ const loadSignUpStrategies = async () => {
224
+ try {
225
+ const strategies = await api.auth.getSignUpStrategies();
226
+ setSignUpState({
227
+ strategies: strategies.reduce((acc, {
228
+ isActive,
229
+ strategy,
230
+ isRequired
231
+ }) => {
232
+ acc[strategy] = {
233
+ enabled: isActive,
234
+ required: isRequired
235
+ };
236
+ return acc;
237
+ }, {})
238
+ });
239
+ } catch (error) {}
240
+ };
158
241
  return {
159
242
  setSignUpState,
160
243
  resetSignUpState,
161
244
  resetSignUpStateSoft,
162
245
  signUpUser,
163
- loadAllowSignUps
246
+ signUpUserWithPhoneNumber,
247
+ loadAllowSignUps,
248
+ loadSignUpStrategies
164
249
  };
165
250
  });
@@ -1,4 +1,4 @@
1
- import { FronteggApiError, ISignUpUser } from '@frontegg/rest-api';
1
+ import { FronteggApiError, ISignUpUser, SignUpStrategyEnum } from '@frontegg/rest-api';
2
2
  import { CustomEventsOptions } from '../interfaces';
3
3
  export interface SignUpState {
4
4
  loading: boolean;
@@ -9,10 +9,17 @@ export interface SignUpState {
9
9
  firstLoad: boolean;
10
10
  shouldActivate?: boolean;
11
11
  stage: SignUpStage;
12
+ phoneNumber?: string;
13
+ otcToken?: string;
14
+ strategies: Partial<Record<SignUpStrategyEnum, {
15
+ enabled: boolean;
16
+ required: boolean;
17
+ }>>;
12
18
  }
13
19
  export declare enum SignUpStage {
14
20
  SignUp = "SignUp",
15
- SignUpSuccess = "SignUpSuccess"
21
+ SignUpSuccess = "SignUpSuccess",
22
+ VerifyPhone = "VerifyPhone"
16
23
  }
17
24
  export interface ISignUpUserPayload extends ISignUpUser {
18
25
  events?: CustomEventsOptions;
@@ -2,4 +2,5 @@ export let SignUpStage;
2
2
  (function (SignUpStage) {
3
3
  SignUpStage["SignUp"] = "SignUp";
4
4
  SignUpStage["SignUpSuccess"] = "SignUpSuccess";
5
+ SignUpStage["VerifyPhone"] = "VerifyPhone";
5
6
  })(SignUpStage || (SignUpStage = {}));
@@ -1,10 +1,21 @@
1
1
  import { SignUpStage } from './interfaces';
2
2
  import { createProxy } from '../../toolkit/proxy';
3
+ import { SignUpStrategyEnum } from '@frontegg/rest-api';
3
4
  export const initialState = {
4
5
  loading: false,
5
6
  allowSignUps: false,
6
7
  allowNotVerifiedUsersLogin: false,
7
8
  firstLoad: true,
8
- stage: SignUpStage.SignUp
9
+ stage: SignUpStage.SignUp,
10
+ strategies: {
11
+ [SignUpStrategyEnum.Email]: {
12
+ enabled: true,
13
+ required: false
14
+ },
15
+ [SignUpStrategyEnum.PhoneNumber]: {
16
+ enabled: true,
17
+ required: true
18
+ }
19
+ }
9
20
  };
10
21
  export default (overrideState => createProxy(initialState, overrideState));
package/auth/helpers.d.ts CHANGED
@@ -8,14 +8,5 @@ export declare const isMfaRequired: (user: ILoginResponse, appName: string) => b
8
8
  export declare const isResetPasswordRequired: (user: ILoginResponse, appName: string) => boolean;
9
9
  export declare const mapMetaDataObjectToActions: (obj: any, path?: string[]) => CommitChangeDto[];
10
10
  export declare const getUri: (urlStrategy: FronteggState["root"]["urlStrategy"]) => string;
11
- export declare const extractPhoneNumber: ({ phoneNumber, ...rest }: ISignUpUser) => {
12
- email: string;
13
- companyName: string;
14
- recaptchaToken?: string;
15
- name?: string;
16
- password?: string;
17
- metadata?: string;
18
- roleIds?: string[];
19
- invitationToken?: string;
20
- };
11
+ export declare const prepareIdentifiersForSignup: (payload: ISignUpUser) => ISignUpUser;
21
12
  export declare const isAuthRoute: (path: string, routes?: Partial<AuthPageRoutes>) => boolean;
package/auth/helpers.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["phoneNumber"],
3
+ const _excluded = ["phoneNumber", "email"],
4
4
  _excluded2 = ["authenticatedUrl"];
5
5
  import { ContextHolder } from '@frontegg/rest-api';
6
6
  import { defaultFronteggRoutes } from './LoginState/consts';
@@ -53,9 +53,23 @@ export const getUri = urlStrategy => {
53
53
  }
54
54
  }
55
55
  };
56
- export const extractPhoneNumber = _ref => {
57
- let rest = _objectWithoutPropertiesLoose(_ref, _excluded);
58
- return rest;
56
+ export const prepareIdentifiersForSignup = payload => {
57
+ const {
58
+ phoneNumber,
59
+ email
60
+ } = payload,
61
+ finalDto = _objectWithoutPropertiesLoose(payload, _excluded);
62
+ if (email != null && email.length) {
63
+ Object.assign(finalDto, {
64
+ email
65
+ });
66
+ }
67
+ if (phoneNumber != null && phoneNumber.length) {
68
+ Object.assign(finalDto, {
69
+ phoneNumber
70
+ });
71
+ }
72
+ return finalDto;
59
73
  };
60
74
  export const isAuthRoute = (path, routes) => {
61
75
  const _defaultFronteggRoute = _extends({}, defaultFronteggRoutes, routes),
@@ -257,7 +257,8 @@ export declare enum UserVerifiedOriginTypes {
257
257
  }
258
258
  export declare enum AuthenticationTypes {
259
259
  SOCIAL_LOGIN = "SOCIAL_LOGIN",
260
- PASSWORD = "PASSWORD"
260
+ PASSWORD = "PASSWORD",
261
+ PHONE_NUMBER = "PHONE_NUMBER"
261
262
  }
262
263
  export declare enum AdminPortalPagesForEvents {
263
264
  profile = "profile",
@@ -314,7 +315,7 @@ export interface ISignUpCompletePayload {
314
315
  name?: string;
315
316
  companyName?: string;
316
317
  phoneNumber?: string;
317
- email: string;
318
+ email?: string;
318
319
  id?: string;
319
320
  createdAt?: Date;
320
321
  tenantId?: string;
@@ -18,6 +18,7 @@ export let AuthenticationTypes;
18
18
  (function (AuthenticationTypes) {
19
19
  AuthenticationTypes["SOCIAL_LOGIN"] = "SOCIAL_LOGIN";
20
20
  AuthenticationTypes["PASSWORD"] = "PASSWORD";
21
+ AuthenticationTypes["PHONE_NUMBER"] = "PHONE_NUMBER";
21
22
  })(AuthenticationTypes || (AuthenticationTypes = {}));
22
23
  export let AdminPortalPagesForEvents;
23
24
 
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.65.0
1
+ /** @license Frontegg v7.67.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.
@@ -4,6 +4,8 @@ declare const _default: (store: FronteggState, api: RestApi, actions: SharedActi
4
4
  resetSignUpState: () => void;
5
5
  resetSignUpStateSoft: () => void;
6
6
  signUpUser: (_payload: import("../..").ISignUpUserPayload) => Promise<void>;
7
+ signUpUserWithPhoneNumber: (_payload: import("../..").ISignUpUserPayload) => Promise<void>;
7
8
  loadAllowSignUps: (payload?: import("../../interfaces").WithCallback<import("../../interfaces").WithRetryConfig<{}>, import("dist/@frontegg/rest-api").IVendorConfig>) => Promise<void>;
9
+ loadSignUpStrategies: () => Promise<void>;
8
10
  };
9
11
  export default _default;
@@ -285,6 +285,7 @@ var _default = (store, api, sharedActions) => {
285
285
  calls.push(actions.loadSocialLoginsConfigurationV2((0, _helpers.withRetryConfig)()));
286
286
  calls.push(actions.loadAllowSignUps(getRetryWithBlockingCallbackPayload(_interfaces2.REQUEST_NAME.LOAD_ALLOW_SIGNUPS)));
287
287
  calls.push(actions.loadPublicAuthStrategiesPolicy(getRetryWithBlockingCallbackPayload(_interfaces2.REQUEST_NAME.LOAD_PUBLIC_AUTH_STRATEGIES_POLICY)));
288
+ calls.push(actions.loadSignUpStrategies());
288
289
  calls.push(__loadSSOPublicConfigurationFunction(getRetryWithBlockingCallbackPayload(_interfaces2.REQUEST_NAME.LOAD_SSO_PUBLIC_CONFIGURATION)));
289
290
  calls.push(actions.loadVendorPublicInfo((0, _helpers.withRetryConfig)()));
290
291
  calls.push(__refreshMetadata((0, _helpers.withRetryConfig)()));
@@ -308,6 +309,7 @@ var _default = (store, api, sharedActions) => {
308
309
  calls.push(actions.loadSocialLoginsConfigurationV2((0, _helpers.withRetryConfig)()));
309
310
  calls.push(actions.loadAllowSignUps(getRetryWithBlockingCallbackPayload(_interfaces2.REQUEST_NAME.LOAD_ALLOW_SIGNUPS)));
310
311
  calls.push(__loadSSOPublicConfigurationFunction(getRetryWithBlockingCallbackPayload(_interfaces2.REQUEST_NAME.LOAD_SSO_PUBLIC_CONFIGURATION)));
312
+ calls.push(actions.loadSignUpStrategies());
311
313
  calls.push(actions.loadVendorPublicInfo((0, _helpers.withRetryConfig)()));
312
314
  calls.push(__refreshMetadata());
313
315
  calls.push(__isMFARequiredSSR(payload));
@@ -15,7 +15,9 @@ var _helpers2 = require("../helpers");
15
15
  var _interfaces2 = require("../interfaces");
16
16
  var _gtm = require("../../helpers/gtm");
17
17
  var _constants = require("../../constants");
18
- const _excluded = ["events", "url"];
18
+ var _toolkit = require("../../toolkit");
19
+ const _excluded = ["events", "url"],
20
+ _excluded2 = ["events", "url"];
19
21
  var _default = (store, api, sharedActions) => {
20
22
  const actions = sharedActions;
21
23
  const contextHolder = _restApi.ContextHolder.for(store.root.appName);
@@ -36,15 +38,101 @@ var _default = (store, api, sharedActions) => {
36
38
  allowNotVerifiedUsersLogin
37
39
  });
38
40
  };
39
- const signUpUser = async _payload => {
41
+ const reportSignupCompletion = (payload, userId, tenantId, activationToken, events, authenticationType = _interfaces2.AuthenticationTypes.PASSWORD) => {
42
+ var _events$signUpComplet;
43
+ const {
44
+ email,
45
+ name,
46
+ companyName,
47
+ phoneNumber,
48
+ url
49
+ } = payload;
50
+ const signUpCompletePayload = {
51
+ email,
52
+ name,
53
+ companyName,
54
+ url,
55
+ phoneNumber: phoneNumber || undefined,
56
+ authenticationType,
57
+ id: userId,
58
+ tenantId,
59
+ createdAt: new Date(),
60
+ activationToken
61
+ };
62
+ events == null ? void 0 : (_events$signUpComplet = events.signUpComplete) == null ? void 0 : _events$signUpComplet.call(events, signUpCompletePayload);
63
+ (0, _gtm.reportGTMEvent)(_gtm.GTMEventAction.SIGNUP_COMPLETED, signUpCompletePayload);
64
+ };
65
+ const signUpUserWithPhoneNumber = async _payload => {
40
66
  const {
41
- events,
42
- url
67
+ events
43
68
  } = _payload,
44
69
  payload = (0, _objectWithoutPropertiesLoose2.default)(_payload, _excluded);
45
70
  setSignUpState({
46
71
  loading: true
47
72
  });
73
+ if (!payload.phoneNumber) {
74
+ throw new Error('Phone number is required for phone number signup');
75
+ }
76
+ try {
77
+ var _store$auth$securityP, _grecaptcha, _grecaptcha$execute;
78
+ const {
79
+ routes,
80
+ onRedirectTo
81
+ } = store.auth;
82
+ const {
83
+ tenantId,
84
+ userId,
85
+ activationToken
86
+ } = await api.auth.signUpUserWithPhoneNumber((0, _helpers2.prepareIdentifiersForSignup)(payload));
87
+ if (!payload.invitationToken) {
88
+ reportSignupCompletion(payload, userId, tenantId, activationToken, events, _interfaces2.AuthenticationTypes.PHONE_NUMBER);
89
+ }
90
+ const {
91
+ enabled: captchaEnabled,
92
+ siteKey
93
+ } = (_store$auth$securityP = store.auth.securityPolicyState.captchaPolicy.policy) != null ? _store$auth$securityP : {};
94
+ const recaptchaToken = captchaEnabled && siteKey ? await ((_grecaptcha = window.grecaptcha) == null ? void 0 : (_grecaptcha$execute = _grecaptcha.execute) == null ? void 0 : _grecaptcha$execute.call(_grecaptcha, {
95
+ action: 'login'
96
+ })) : '';
97
+ actions.passwordlessPreLogin({
98
+ recaptchaToken,
99
+ phoneNumber: payload.phoneNumber,
100
+ type: _restApi.AuthStrategyEnum.SmsCode,
101
+ callback: (success, error) => {
102
+ if (!success && error) {
103
+ throw error;
104
+ }
105
+ onRedirectTo(routes.loginUrl);
106
+ actions.setLoginState({
107
+ step: _toolkit.LoginStep.loginWithSmsOtc,
108
+ phoneNumber: payload.phoneNumber
109
+ });
110
+ }
111
+ });
112
+ } catch (e) {
113
+ contextHolder.setAccessToken(null);
114
+ contextHolder.setUser(null);
115
+ setSignUpState({
116
+ error: (0, _helpers.errorHandler)(e)
117
+ });
118
+ } finally {
119
+ setSignUpState({
120
+ loading: false
121
+ });
122
+ }
123
+ };
124
+ const signUpUser = async _payload => {
125
+ const {
126
+ events
127
+ } = _payload,
128
+ payload = (0, _objectWithoutPropertiesLoose2.default)(_payload, _excluded2);
129
+ setSignUpState({
130
+ loading: true
131
+ });
132
+ const phoneNumberStrategy = store.auth.signUpState.strategies.phoneNumber;
133
+ if (phoneNumberStrategy != null && phoneNumberStrategy.required && phoneNumberStrategy != null && phoneNumberStrategy.enabled && payload.phoneNumber) {
134
+ return signUpUserWithPhoneNumber(_payload);
135
+ }
48
136
  try {
49
137
  const {
50
138
  routes,
@@ -58,32 +146,9 @@ var _default = (store, api, sharedActions) => {
58
146
  tenants = [],
59
147
  activeTenant,
60
148
  activationToken
61
- } = await api.auth.signUpUser(
62
- //Currently we are not supporting phone number in signup in the backend
63
- //Remove this line when we will support it (also make sure when field is optional no empty string is sent)
64
- (0, _helpers2.extractPhoneNumber)(payload));
149
+ } = await api.auth.signUpUser((0, _helpers2.prepareIdentifiersForSignup)(payload));
65
150
  if (!payload.invitationToken) {
66
- var _events$signUpComplet;
67
- const {
68
- email,
69
- name,
70
- companyName,
71
- phoneNumber
72
- } = payload;
73
- const signUpCompletePayload = {
74
- email,
75
- name,
76
- companyName,
77
- url,
78
- phoneNumber: phoneNumber || undefined,
79
- authenticationType: _interfaces2.AuthenticationTypes.PASSWORD,
80
- id: userId,
81
- tenantId,
82
- createdAt: new Date(),
83
- activationToken
84
- };
85
- events == null ? void 0 : (_events$signUpComplet = events.signUpComplete) == null ? void 0 : _events$signUpComplet.call(events, signUpCompletePayload);
86
- (0, _gtm.reportGTMEvent)(_gtm.GTMEventAction.SIGNUP_COMPLETED, signUpCompletePayload);
151
+ reportSignupCompletion(payload, userId, tenantId, activationToken, events);
87
152
  }
88
153
  if (!shouldActivate && user && (0, _helpers2.isMfaRequired)(user, store.root.appName)) {
89
154
  const mfaRequiredState = await actions.getMfaRequiredState(user, _constants.DEFAULT_RETRY_CONFIG, true, payload.email);
@@ -162,12 +227,32 @@ var _default = (store, api, sharedActions) => {
162
227
  payload == null ? void 0 : (_payload$callback2 = payload.callback) == null ? void 0 : _payload$callback2.call(payload, null, e);
163
228
  }
164
229
  };
230
+ const loadSignUpStrategies = async () => {
231
+ try {
232
+ const strategies = await api.auth.getSignUpStrategies();
233
+ setSignUpState({
234
+ strategies: strategies.reduce((acc, {
235
+ isActive,
236
+ strategy,
237
+ isRequired
238
+ }) => {
239
+ acc[strategy] = {
240
+ enabled: isActive,
241
+ required: isRequired
242
+ };
243
+ return acc;
244
+ }, {})
245
+ });
246
+ } catch (error) {}
247
+ };
165
248
  return {
166
249
  setSignUpState,
167
250
  resetSignUpState,
168
251
  resetSignUpStateSoft,
169
252
  signUpUser,
170
- loadAllowSignUps
253
+ signUpUserWithPhoneNumber,
254
+ loadAllowSignUps,
255
+ loadSignUpStrategies
171
256
  };
172
257
  };
173
258
  exports.default = _default;
@@ -9,4 +9,5 @@ exports.SignUpStage = SignUpStage;
9
9
  (function (SignUpStage) {
10
10
  SignUpStage["SignUp"] = "SignUp";
11
11
  SignUpStage["SignUpSuccess"] = "SignUpSuccess";
12
+ SignUpStage["VerifyPhone"] = "VerifyPhone";
12
13
  })(SignUpStage || (exports.SignUpStage = SignUpStage = {}));
@@ -6,12 +6,23 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.initialState = exports.default = void 0;
7
7
  var _interfaces = require("./interfaces");
8
8
  var _proxy = require("../../toolkit/proxy");
9
+ var _restApi = require("@frontegg/rest-api");
9
10
  const initialState = {
10
11
  loading: false,
11
12
  allowSignUps: false,
12
13
  allowNotVerifiedUsersLogin: false,
13
14
  firstLoad: true,
14
- stage: _interfaces.SignUpStage.SignUp
15
+ stage: _interfaces.SignUpStage.SignUp,
16
+ strategies: {
17
+ [_restApi.SignUpStrategyEnum.Email]: {
18
+ enabled: true,
19
+ required: false
20
+ },
21
+ [_restApi.SignUpStrategyEnum.PhoneNumber]: {
22
+ enabled: true,
23
+ required: true
24
+ }
25
+ }
15
26
  };
16
27
  exports.initialState = initialState;
17
28
  var _default = overrideState => (0, _proxy.createProxy)(initialState, overrideState);
@@ -9,10 +9,10 @@ var _exportNames = {
9
9
  isResetPasswordRequired: true,
10
10
  mapMetaDataObjectToActions: true,
11
11
  getUri: true,
12
- extractPhoneNumber: true,
12
+ prepareIdentifiersForSignup: true,
13
13
  isAuthRoute: true
14
14
  };
15
- exports.mapMetaDataObjectToActions = exports.isResetPasswordRequired = exports.isMfaRequired = exports.isAuthRoute = exports.getUri = exports.extractPhoneNumber = void 0;
15
+ exports.prepareIdentifiersForSignup = exports.mapMetaDataObjectToActions = exports.isResetPasswordRequired = exports.isMfaRequired = exports.isAuthRoute = exports.getUri = void 0;
16
16
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
17
17
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
18
18
  var _restApi = require("@frontegg/rest-api");
@@ -53,7 +53,7 @@ Object.keys(_helpers3).forEach(function (key) {
53
53
  }
54
54
  });
55
55
  });
56
- const _excluded = ["phoneNumber"],
56
+ const _excluded = ["phoneNumber", "email"],
57
57
  _excluded2 = ["authenticatedUrl"];
58
58
  const isMfaRequired = (user, appName) => {
59
59
  const contextHolder = _restApi.ContextHolder.for(appName);
@@ -105,11 +105,25 @@ const getUri = urlStrategy => {
105
105
  }
106
106
  };
107
107
  exports.getUri = getUri;
108
- const extractPhoneNumber = _ref => {
109
- let rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
110
- return rest;
108
+ const prepareIdentifiersForSignup = payload => {
109
+ const {
110
+ phoneNumber,
111
+ email
112
+ } = payload,
113
+ finalDto = (0, _objectWithoutPropertiesLoose2.default)(payload, _excluded);
114
+ if (email != null && email.length) {
115
+ Object.assign(finalDto, {
116
+ email
117
+ });
118
+ }
119
+ if (phoneNumber != null && phoneNumber.length) {
120
+ Object.assign(finalDto, {
121
+ phoneNumber
122
+ });
123
+ }
124
+ return finalDto;
111
125
  };
112
- exports.extractPhoneNumber = extractPhoneNumber;
126
+ exports.prepareIdentifiersForSignup = prepareIdentifiersForSignup;
113
127
  const isAuthRoute = (path, routes) => {
114
128
  const _defaultFronteggRoute = (0, _extends2.default)({}, _consts.defaultFronteggRoutes, routes),
115
129
  authRoutes = (0, _objectWithoutPropertiesLoose2.default)(_defaultFronteggRoute, _excluded2);
@@ -27,6 +27,7 @@ exports.AuthenticationTypes = AuthenticationTypes;
27
27
  (function (AuthenticationTypes) {
28
28
  AuthenticationTypes["SOCIAL_LOGIN"] = "SOCIAL_LOGIN";
29
29
  AuthenticationTypes["PASSWORD"] = "PASSWORD";
30
+ AuthenticationTypes["PHONE_NUMBER"] = "PHONE_NUMBER";
30
31
  })(AuthenticationTypes || (exports.AuthenticationTypes = AuthenticationTypes = {}));
31
32
  let AdminPortalPagesForEvents; // noinspection JSUnusedGlobalSymbols
32
33
  exports.AdminPortalPagesForEvents = AdminPortalPagesForEvents;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.65.0
1
+ /** @license Frontegg v7.67.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.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "7.65.0",
3
+ "version": "7.67.0-alpha.0",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.18.6",
9
9
  "@frontegg/entitlements-javascript-commons": "1.1.2",
10
- "@frontegg/rest-api": "7.65.0",
10
+ "@frontegg/rest-api": "7.67.0-alpha.0",
11
11
  "fast-deep-equal": "3.1.3",
12
12
  "get-value": "^3.0.1",
13
13
  "proxy-compare": "^3.0.0",