verifyTOTP method

Future<void> verifyTOTP(
  1. String code
)

Verifies the TOTP setup with the given code

Implementation

Future<void> verifyTOTP(
  String code,
) async {
  emit(state.startLoading(verifyTOTPLoading));

  try {
    await provider.verifyTOTP(code);
    emit(state.copyWith(
      resetTOTPSetup: true,
    ));
  } on InvalidCodeException catch (error, stackTrace) {
    emit(state.addMessage(
      Message.error(_localizations.invalidVerificationCode),
      error,
      stackTrace,
    ));
  } on ExpiredCodeException catch (error, stackTrace) {
    emit(state.addMessage(
      Message.error(_localizations.expiredVerificationCode),
      error,
      stackTrace,
    ));
  } on TOTPVerifyException catch (error, stackTrace) {
    emit(state.addMessage(
      Message.error(
        _localizations.totpVerifyError(error.message),
      ),
      error,
      stackTrace,
    ));
  } finally {
    emit(state.endLoading(verifyTOTPLoading));
  }
}