From cf2da85776c3ef943ddde1d5ec0f914f03f704f1 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:33:17 -0700 Subject: [PATCH] chore: use confirmSignInWithEmailMfaCode instead of confirmSignInMfa --- .../lib/amplify_authenticator.dart | 1 + .../lib/src/blocs/auth/auth_bloc.dart | 7 +++++-- .../src/l10n/generated/title_localizations.dart | 4 ++-- .../l10n/generated/title_localizations_en.dart | 4 ++-- .../lib/src/screens/authenticator_screen.dart | 7 ++++--- .../lib/src/state/auth_state.dart | 3 +++ .../lib/src/state/authenticator_state.dart | 17 +++++++++++++++++ .../lib/src/state/inherited_forms.dart | 6 +++++- .../lib/src/widgets/form_field.dart | 3 ++- 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/packages/authenticator/amplify_authenticator/lib/amplify_authenticator.dart b/packages/authenticator/amplify_authenticator/lib/amplify_authenticator.dart index f83b9b84c4..55abb9c220 100644 --- a/packages/authenticator/amplify_authenticator/lib/amplify_authenticator.dart +++ b/packages/authenticator/amplify_authenticator/lib/amplify_authenticator.dart @@ -719,6 +719,7 @@ class _AuthenticatorState extends State { continueSignInWithEmailMfaSetupForm: ContinueSignInWithEmailMfaSetupForm(), confirmSignInWithTotpMfaCodeForm: ConfirmSignInMFAForm(), + confirmSignInWithEmailMfaCodeForm: ConfirmSignInMFAForm(), verifyUserForm: VerifyUserForm(), confirmVerifyUserForm: ConfirmVerifyUserForm(), child: widget.child, diff --git a/packages/authenticator/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart b/packages/authenticator/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart index 0b8dd7f2ee..6c97ccd96d 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart @@ -218,7 +218,6 @@ class StateMachineBloc switch (result.nextStep.signInStep) { case AuthSignInStep.confirmSignInWithSmsMfaCode: - case AuthSignInStep.confirmSignInWithEmailMfaCode: yield UnauthenticatedState.confirmSignInMfa; case AuthSignInStep.confirmSignInWithCustomChallenge: yield ConfirmSignInCustom( @@ -228,6 +227,8 @@ class StateMachineBloc yield UnauthenticatedState.confirmSignInNewPassword; case AuthSignInStep.confirmSignInWithTotpMfaCode: yield UnauthenticatedState.confirmSignInWithTotpMfaCode; + case AuthSignInStep.confirmSignInWithEmailMfaCode: + yield UnauthenticatedState.confirmSignInWithEmailMfaCode; case AuthSignInStep.continueSignInWithMfaSelection: yield ContinueSignInWithMfaSelection( allowedMfaTypes: result.nextStep.allowedMfaTypes, @@ -322,7 +323,6 @@ class StateMachineBloc }) async { switch (result.nextStep.signInStep) { case AuthSignInStep.confirmSignInWithSmsMfaCode: - case AuthSignInStep.confirmSignInWithEmailMfaCode: _notifyCodeSent(result.nextStep.codeDeliveryDetails?.destination); _emit(UnauthenticatedState.confirmSignInMfa); case AuthSignInStep.confirmSignInWithCustomChallenge: @@ -360,6 +360,9 @@ class StateMachineBloc _emit(UnauthenticatedState.continueSignInWithEmailMfaSetup); case AuthSignInStep.confirmSignInWithTotpMfaCode: _emit(UnauthenticatedState.confirmSignInWithTotpMfaCode); + case AuthSignInStep.confirmSignInWithEmailMfaCode: + _notifyCodeSent(result.nextStep.codeDeliveryDetails?.destination); + _emit(UnauthenticatedState.confirmSignInWithEmailMfaCode); case AuthSignInStep.resetPassword: _emit(UnauthenticatedState.confirmResetPassword); case AuthSignInStep.confirmSignUp: diff --git a/packages/authenticator/amplify_authenticator/lib/src/l10n/generated/title_localizations.dart b/packages/authenticator/amplify_authenticator/lib/src/l10n/generated/title_localizations.dart index 05d73ef2a4..852f8e4d7b 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/l10n/generated/title_localizations.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/l10n/generated/title_localizations.dart @@ -150,13 +150,13 @@ abstract class AuthenticatorTitleLocalizations { /// Title of the Continue Sign In with Email MFA Setup step and form /// /// In en, this message translates to: - /// **'Set up Email Two-Factor Auth'** + /// **'Add Email for Two-Factor Authentication'** String get continueSignInWithEmailMfaSetup; /// Title of the Continue Sign In with MFA Setup Selection step and form /// /// In en, this message translates to: - /// **'Select a Two-Factor Auth method to set up'** + /// **'Choose your preferred two-factor authentication method to set up'** String get continueSignInWithMfaSetupSelection; /// Title of the Reset Password step and form diff --git a/packages/authenticator/amplify_authenticator/lib/src/l10n/generated/title_localizations_en.dart b/packages/authenticator/amplify_authenticator/lib/src/l10n/generated/title_localizations_en.dart index 3f3ca2b794..f547339bf5 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/l10n/generated/title_localizations_en.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/l10n/generated/title_localizations_en.dart @@ -34,11 +34,11 @@ class AuthenticatorTitleLocalizationsEn String get confirmSignInWithEmailMfaCode => 'Enter your one-time passcode'; @override - String get continueSignInWithEmailMfaSetup => 'Set up Email Two-Factor Auth'; + String get continueSignInWithEmailMfaSetup => 'Add Email for Two-Factor Authentication'; @override String get continueSignInWithMfaSetupSelection => - 'Select a Two-Factor Auth method to set up'; + 'Choose your preferred two-factor authentication method to set up'; @override String get resetPassword => 'Send Code'; diff --git a/packages/authenticator/amplify_authenticator/lib/src/screens/authenticator_screen.dart b/packages/authenticator/amplify_authenticator/lib/src/screens/authenticator_screen.dart index b5d48988b1..e547dfd9f0 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/screens/authenticator_screen.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/screens/authenticator_screen.dart @@ -40,13 +40,14 @@ class AuthenticatorScreen extends StatelessAuthenticatorComponent { const AuthenticatorScreen.confirmSignInWithTotpMfaCode({Key? key}) : this(key: key, step: AuthenticatorStep.confirmSignInWithTotpMfaCode); + const AuthenticatorScreen.confirmSignInWithEmailMfaCode({Key? key}) + : this(key: key, step: AuthenticatorStep.confirmSignInWithEmailMfaCode); + const AuthenticatorScreen.continueSignInWithEmailMfaSetup({Key? key}) : this(key: key, step: AuthenticatorStep.continueSignInWithEmailMfaSetup); const AuthenticatorScreen.continueSignInWithMfaSetupSelection({Key? key}) - : this( - key: key, - step: AuthenticatorStep.continueSignInWithMfaSetupSelection); + : this(key: key, step: AuthenticatorStep.continueSignInWithMfaSetupSelection); const AuthenticatorScreen.resetPassword({Key? key}) : this(key: key, step: AuthenticatorStep.resetPassword); diff --git a/packages/authenticator/amplify_authenticator/lib/src/state/auth_state.dart b/packages/authenticator/amplify_authenticator/lib/src/state/auth_state.dart index 819900715e..834afbe683 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/state/auth_state.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/state/auth_state.dart @@ -49,6 +49,9 @@ class UnauthenticatedState extends AuthState static const continueSignInWithEmailMfaSetup = UnauthenticatedState( step: AuthenticatorStep.continueSignInWithEmailMfaSetup, ); + static const confirmSignInWithEmailMfaCode = UnauthenticatedState( + step: AuthenticatorStep.confirmSignInWithEmailMfaCode, + ); static const resetPassword = UnauthenticatedState(step: AuthenticatorStep.resetPassword); static const confirmResetPassword = diff --git a/packages/authenticator/amplify_authenticator/lib/src/state/authenticator_state.dart b/packages/authenticator/amplify_authenticator/lib/src/state/authenticator_state.dart index 8e4b5542e4..bf434aba5c 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/state/authenticator_state.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/state/authenticator_state.dart @@ -426,6 +426,23 @@ class AuthenticatorState extends ChangeNotifier { _setIsBusy(false); } + /// complete Email MFA setup using the values for [confirmationCode] + Future confirmEmailMfa() async { + if (!_formKey.currentState!.validate()) { + return; + } + + _setIsBusy(true); + + final confirm = AuthConfirmSignInData( + confirmationValue: _confirmationCode.trim(), + ); + + _authBloc.add(AuthConfirmSignIn(confirm)); + await nextBlocEvent(); + _setIsBusy(false); + } + /// Complete MFA setup using the values for [confirmationCode] Future continueEmailMfaSetup() async { if (!_formKey.currentState!.validate()) { diff --git a/packages/authenticator/amplify_authenticator/lib/src/state/inherited_forms.dart b/packages/authenticator/amplify_authenticator/lib/src/state/inherited_forms.dart index 876164b22a..121f81bd0d 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/state/inherited_forms.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/state/inherited_forms.dart @@ -20,6 +20,7 @@ class InheritedForms extends InheritedWidget { required this.continueSignInWithTotpSetupForm, required this.continueSignInWithEmailMfaSetupForm, required this.confirmSignInWithTotpMfaCodeForm, + required this.confirmSignInWithEmailMfaCodeForm, required this.verifyUserForm, required this.confirmVerifyUserForm, required super.child, @@ -37,6 +38,7 @@ class InheritedForms extends InheritedWidget { final ContinueSignInWithTotpSetupForm continueSignInWithTotpSetupForm; final ContinueSignInWithEmailMfaSetupForm continueSignInWithEmailMfaSetupForm; final ConfirmSignInMFAForm confirmSignInWithTotpMfaCodeForm; + final ConfirmSignInMFAForm confirmSignInWithEmailMfaCodeForm; final ResetPasswordForm resetPasswordForm; final ConfirmResetPasswordForm confirmResetPasswordForm; final VerifyUserForm verifyUserForm; @@ -69,7 +71,7 @@ class InheritedForms extends InheritedWidget { case AuthenticatorStep.continueSignInWithEmailMfaSetup: return continueSignInWithEmailMfaSetupForm; case AuthenticatorStep.confirmSignInWithEmailMfaCode: - return confirmSignInMFAForm; + return confirmSignInWithEmailMfaCodeForm; case AuthenticatorStep.resetPassword: return resetPasswordForm; case AuthenticatorStep.confirmResetPassword: @@ -116,6 +118,8 @@ class InheritedForms extends InheritedWidget { continueSignInWithTotpSetupForm || oldWidget.confirmSignInWithTotpMfaCodeForm != confirmSignInWithTotpMfaCodeForm || + oldWidget.confirmSignInWithEmailMfaCodeForm != + confirmSignInWithEmailMfaCodeForm || oldWidget.continueSignInWithEmailMfaSetupForm != continueSignInWithEmailMfaSetupForm || oldWidget.continueSignInWithMfaSelectionForm != diff --git a/packages/authenticator/amplify_authenticator/lib/src/widgets/form_field.dart b/packages/authenticator/amplify_authenticator/lib/src/widgets/form_field.dart index 1c4477b91b..a9824be8c5 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/widgets/form_field.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/widgets/form_field.dart @@ -230,8 +230,9 @@ abstract class AuthenticatorFormFieldState< case AuthenticatorStep.confirmSignInCustomAuth: state.confirmSignInCustomAuth(); case AuthenticatorStep.confirmSignInMfa: - case AuthenticatorStep.confirmSignInWithEmailMfaCode: state.confirmSignInMFA(); + case AuthenticatorStep.confirmSignInWithEmailMfaCode: + state.confirmEmailMfa(); case AuthenticatorStep.confirmSignInNewPassword: state.confirmSignInNewPassword(); case AuthenticatorStep.confirmSignInWithTotpMfaCode: