sendNewPhoneOTP method

Future<Map<String, dynamic>> sendNewPhoneOTP({
  1. required String tenantId,
  2. required String phoneNumber,
  3. required String newPhoneNumber,
})

Step 3: Send OTP to new phone number

Implementation

Future<Map<String, dynamic>> sendNewPhoneOTP({
  required String tenantId,
  required String phoneNumber,
  required String newPhoneNumber,
}) async {
  const query = r'''
    mutation SendNewPhoneOTP($input: PhoneChangeInput!) {
      sendNewPhoneOTP(input: $input) {
        success
        message
        otpSent
      }
    }
  ''';

  final normalizedOldPhone = _normalizePhone(phoneNumber);
  final normalizedNewPhone = _normalizePhone(newPhoneNumber);

  try {
    final res = await _api.graphql(query, {
      'input': {
        'tenantID': tenantId,
        'phoneNumber': normalizedOldPhone,
        'newPhoneNumber': normalizedNewPhone,
      }
    });

    final data = res['sendNewPhoneOTP'];
    if (data == null) {
      return {
        'success': false,
        'message': 'No data returned from server',
      };
    }

    return Map<String, dynamic>.from(data);
  } catch (e) {
    print("ERROR sending new phone OTP: $e");
    return {
      'success': false,
      'message': 'Failed to send OTP: $e',
    };
  }
}