requestOTP method

Future<OTPResponse> requestOTP({
  1. required String email,
  2. String? tenantId,
})

Request OTP for email login

Implementation

Future<OTPResponse> requestOTP({
  required String email,
  String? tenantId,
}) async {
  try {
    print('🚀 AuthService.requestOTP called');
    print('   Email: $email');
    print('   TenantId: $tenantId');

    final response = await _apiClient.post<Map<String, dynamic>>(
      '/api/v1/auth/request-otp',
      data: {
        'email': email,
        if (tenantId != null) 'tenantId': tenantId,
      },
    );

    print('✅ AuthService.requestOTP API response received');
    print('   Response: $response');

    final otpResponse = OTPResponse.fromJson(response);
    print('✅ AuthService.requestOTP parsed response');
    print('   Success: ${otpResponse.success}');
    print('   Message: ${otpResponse.message}');
    print('   ExpiresAt: ${otpResponse.expiresAt}');
    print(
        '   RequiresTenantSelection: ${otpResponse.requiresTenantSelection}',);
    print('   DefaultTenantId: ${otpResponse.defaultTenantId}');
    print('   SelectedTenantId: ${otpResponse.selectedTenantId}');
    print('   Tenants: ${otpResponse.tenants?.length}');

    return otpResponse;
  } on ProdobitException {
    rethrow;
  } catch (e) {
    print('❌ AuthService.requestOTP error: $e');
    throw AuthException(
      'Failed to request OTP: $e',
      code: 'OTP_REQUEST_ERROR',
    );
  }
}