InappifyOtpChallenge.fromMap constructor

InappifyOtpChallenge.fromMap(
  1. Map<String, dynamic> map
)

Decodes a challenge response from JavaScript or a future native SDK.

Implementation

factory InappifyOtpChallenge.fromMap(Map<String, dynamic> map) {
  final challengeId = map['challengeId'] ?? map['challenge_id'] ?? map['id'];
  if (challengeId is! String || challengeId.isEmpty) {
    throw const FormatException(
      'OTP challengeId must be a non-empty string.',
    );
  }
  final expiresAt = map['expiresAt'] ?? map['expires_at'];
  final status = map['status'];
  final expiresIn = map['expiresIn'] ?? map['expires_in'];
  if (expiresAt != null && expiresAt is! String) {
    throw const FormatException('OTP expiresAt must be a string or null.');
  }
  if (status != null && status is! String) {
    throw const FormatException('OTP status must be a string or null.');
  }
  if (expiresIn != null &&
      (expiresIn is! num ||
          !expiresIn.isFinite ||
          expiresIn != expiresIn.toInt())) {
    throw const FormatException('OTP expiresIn must be an integer or null.');
  }
  return InappifyOtpChallenge(
    challengeId: challengeId,
    status: status as String?,
    expiresAt: expiresAt as String?,
    expiresIn: (expiresIn as num?)?.toInt(),
  );
}