confirmVerificationCodeForAttribute method

  1. @override
Future<void> confirmVerificationCodeForAttribute(
  1. String attribute,
  2. String code
)
override

Verifies the given attribute with the code that was sent to the user

Implementation

@override
Future<void> confirmVerificationCodeForAttribute(
  String attribute,
  String code,
) async {
  final completer = Completer<void>();

  _amplifyAuth
      .confirmUserAttribute(
    userAttributeKey: _lookupUserAttributeKey(attribute),
    confirmationCode: code,
  )
      .then(
    (result) async {
      _logger.fine(
        'Successfully confirmed user attribute key: $result',
      );
      try {
        _enqueueEvent(
          LoggedInEvent(
            await readUser(),
          ),
        );
      } catch (e, stackTrace) {
        _enqueueErrorEvent(
          ReadUserEventError(
            AppException(
              message: 'Failed to read user details after sign in',
              stackTrace: StackTrace.current,
              innerException: e is Exception ? e : Exception(e),
              innerStackTrace: stackTrace,
            ),
          ),
          StackTrace.current,
        );
      }
      completer.complete();
    },
  ).onError<aws_cognito.CodeMismatchException>((e, stackTrace) {
    completer.completeError(
      InvalidCodeException(
        message: e.message,
        innerException: e,
        innerStackTrace: StackTrace.current,
      ),
    );
  }).onError<aws_cognito.ExpiredCodeException>((e, stackTrace) {
    completer.completeError(
      ExpiredCodeException(
        message: e.message,
        innerException: e,
        innerStackTrace: StackTrace.current,
      ),
    );
  }).onError<aws_cognito.AuthException>(
    (e, stackTrace) {
      completer.completeError(
        ConfirmUserAttributeException(
          message: 'Failed to confirm user attribute $attribute',
          innerException: e,
          innerStackTrace: StackTrace.current,
        ),
      );
    },
  );

  return completer.future;
}