Skip to content

Commit 3defc07

Browse files
Dillon NysJordan-Nelson
authored andcommitted
fix(authenticator): Collect MFA types
Collect phone number during sign up if registered as an MFA type commit-id:00650edb
1 parent 40d8e43 commit 3defc07

File tree

1 file changed

+20
-1
lines changed
  • packages/amplify_authenticator/lib/src/widgets

1 file changed

+20
-1
lines changed

packages/amplify_authenticator/lib/src/widgets/form.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
library authenticator.form;
1717

1818
import 'package:amplify_authenticator/amplify_authenticator.dart';
19+
import 'package:amplify_authenticator/src/enums/enums.dart';
1920
import 'package:amplify_authenticator/src/mixins/authenticator_username_field.dart';
2021
import 'package:amplify_authenticator/src/state/inherited_authenticator_state.dart';
2122
import 'package:amplify_authenticator/src/state/inherited_config.dart';
@@ -293,7 +294,7 @@ class _SignUpFormState extends AuthenticatorFormState<SignUpForm> {
293294
return const [];
294295
}
295296

296-
return runtimeAttributes
297+
final runtimeFields = runtimeAttributes
297298
.map((attr) {
298299
if (attr == CognitoUserAttributeKey.address) {
299300
return SignUpFormField.address(required: true);
@@ -337,6 +338,24 @@ class _SignUpFormState extends AuthenticatorFormState<SignUpForm> {
337338
})
338339
.whereType<SignUpFormField>()
339340
.toList();
341+
342+
final hasSmsMfa = authConfig?.mfaTypes?.contains(MfaType.sms) ?? false;
343+
if (hasSmsMfa) {
344+
final mfaConfiguration =
345+
authConfig?.mfaConfiguration ?? MfaConfiguration.off;
346+
final hasSmsField = runtimeFields.any(
347+
(f) => f.field == SignUpField.phoneNumber,
348+
);
349+
if (!hasSmsField && mfaConfiguration != MfaConfiguration.off) {
350+
runtimeFields.add(
351+
SignUpFormField.phoneNumber(
352+
required: mfaConfiguration == MfaConfiguration.on,
353+
),
354+
);
355+
}
356+
}
357+
358+
return runtimeFields;
340359
}
341360
}
342361

0 commit comments

Comments
 (0)