in packages/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart [243:315]
Stream<AuthState> _signIn(AuthSignInData data) async* {
try {
// Make sure no user is signed in before calling the sign in method
if (await _authService.isLoggedIn) {
await _authService.signOut();
}
final SignInResult result;
final bool isSocialSignIn = data is AuthSocialSignInData;
if (data is AuthUsernamePasswordSignInData) {
result = await _authService.signIn(
data.username,
data.password,
);
} else if (data is AuthSocialSignInData) {
result = await _authService.signInWithProvider(
data.provider,
preferPrivateSession: preferPrivateSession,
);
} else {
throw StateError('Bad sign in data: $data');
}
switch (result.nextStep!.signInStep) {
case 'CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE':
_notifyCodeSent(result.nextStep?.codeDeliveryDetails?.destination);
yield UnauthenticatedState.confirmSignInMfa;
break;
case 'CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE':
_exceptionController.add(const AuthenticatorException.customAuth());
break;
case 'CONFIRM_SIGN_IN_WITH_NEW_PASSWORD':
yield UnauthenticatedState.confirmSignInNewPassword;
break;
case 'RESET_PASSWORD':
yield UnauthenticatedState.confirmResetPassword;
break;
case 'CONFIRM_SIGN_UP':
_notifyCodeSent(result.nextStep?.codeDeliveryDetails?.destination);
yield UnauthenticatedState.confirmSignUp;
break;
case 'DONE':
if (isSocialSignIn) {
yield const AuthenticatedState();
} else {
yield* _checkUserVerification();
}
break;
default:
break;
}
} on UserNotConfirmedException catch (e) {
_exceptionController.add(AuthenticatorException(
e.message,
showBanner: false,
));
yield UnauthenticatedState.confirmSignUp;
if (data is AuthUsernamePasswordSignInData) {
yield* _resendSignUpCode(data.username);
} else {
// TODO: Is this possible?
}
} on AmplifyException catch (e) {
_exceptionController.add(AuthenticatorException(
e.message,
showBanner: !e.message.contains('cancelled'),
));
} on Exception catch (e) {
_exceptionController.add(AuthenticatorException(e.toString()));
}
}