appendOtpHistory method

Future<Map<String, dynamic>> appendOtpHistory({
  1. required String atSign,
  2. required String otp,
  3. String expiry = '',
  4. String? expiresAtUtc,
})

Implementation

Future<Map<String, dynamic>> appendOtpHistory({
  required String atSign,
  required String otp,
  String expiry = '',
  String? expiresAtUtc,
}) async {
  return mutateState(
    atSign: atSign,
    mutate: (state) {
      final history = _normalizeOtpHistory(state['otpHistory']);
      final entry = <String, dynamic>{
        'otp': otp,
        'expiry': expiry,
        'generatedAtUtc': DateTime.now().toUtc().toIso8601String(),
      };
      if (expiresAtUtc != null && expiresAtUtc.trim().isNotEmpty) {
        entry['expiresAtUtc'] = expiresAtUtc.trim();
      }
      history.insert(0, entry);
      state['otpHistory'] = history;
    },
  );
}