@@ -11,6 +11,7 @@ import {
11
11
CfnUserPoolClient ,
12
12
CfnUserPoolGroup ,
13
13
Mfa ,
14
+ MfaSecondFactor ,
14
15
OAuthScope ,
15
16
OidcAttributeRequestMethod ,
16
17
ProviderAttribute ,
@@ -375,6 +376,16 @@ export class AmplifyAuth
375
376
smsMessage : smsMessage ,
376
377
} ;
377
378
}
379
+ const mfaType = this . getMFAType ( props . multifactor ) ;
380
+ const mfaMode = this . getMFAMode ( props . multifactor ) ;
381
+
382
+ // If phone login is enabled along with MFA, cognito requires that mfa SMS type to be enabled.
383
+ if ( phoneEnabled && mfaMode && mfaMode !== 'OFF' && ! mfaType ?. sms ) {
384
+ throw Error (
385
+ 'Invalid MFA settings. SMS must be enabled in multiFactor if loginWith phone is enabled'
386
+ ) ;
387
+ }
388
+
378
389
const userPoolProps : UserPoolProps = {
379
390
signInCaseSensitive : DEFAULTS . SIGN_IN_CASE_SENSITIVE ,
380
391
signInAliases : {
@@ -397,16 +408,9 @@ export class AmplifyAuth
397
408
...( props . userAttributes ? props . userAttributes : { } ) ,
398
409
} ,
399
410
selfSignUpEnabled : DEFAULTS . ALLOW_SELF_SIGN_UP ,
400
- mfa : this . getMFAMode ( props . multifactor ) ,
411
+ mfa : mfaMode ,
401
412
mfaMessage : this . getMFAMessage ( props . multifactor ) ,
402
- mfaSecondFactor :
403
- typeof props . multifactor === 'object' &&
404
- props . multifactor . mode !== 'OFF'
405
- ? {
406
- sms : props . multifactor . sms ? true : false ,
407
- otp : props . multifactor . totp ? true : false ,
408
- }
409
- : undefined ,
413
+ mfaSecondFactor : mfaType ,
410
414
accountRecovery : this . getAccountRecoverySetting (
411
415
emailEnabled ,
412
416
phoneEnabled ,
@@ -542,10 +546,10 @@ export class AmplifyAuth
542
546
} ;
543
547
544
548
/**
545
- * Convert user friendly Mfa mode to cognito Mfa type .
549
+ * Convert user friendly Mfa mode to cognito Mfa Mode .
546
550
* This eliminates the need for users to import cognito.Mfa.
547
551
* @param mfa - MFA settings
548
- * @returns cognito MFA enforcement type
552
+ * @returns cognito MFA enforcement mode
549
553
*/
550
554
private getMFAMode = ( mfa : AuthProps [ 'multifactor' ] ) : Mfa | undefined => {
551
555
if ( mfa ) {
@@ -561,6 +565,23 @@ export class AmplifyAuth
561
565
return undefined ;
562
566
} ;
563
567
568
+ /**
569
+ * Convert user friendly Mfa type to cognito Mfa type.
570
+ * This eliminates the need for users to import cognito.Mfa.
571
+ * @param mfa - MFA settings
572
+ * @returns cognito MFA type (sms or totp)
573
+ */
574
+ private getMFAType = (
575
+ mfa : AuthProps [ 'multifactor' ]
576
+ ) : MfaSecondFactor | undefined => {
577
+ return typeof mfa === 'object' && mfa . mode !== 'OFF'
578
+ ? {
579
+ sms : mfa . sms ? true : false ,
580
+ otp : mfa . totp ? true : false ,
581
+ }
582
+ : undefined ;
583
+ } ;
584
+
564
585
/**
565
586
* Convert user friendly account recovery method to cognito AccountRecover enum.
566
587
* This eliminates the need for users to import cognito.AccountRecovery.
0 commit comments