Fix registration 415: send multipart form data with ID images
All checks were successful
Build frontend / build (push) Successful in 1m10s
All checks were successful
Build frontend / build (push) Successful in 1m10s
- addCustomer/addOwner now use FormData with multipart upload - Front and back ID images appended as FrontIdCarImage/RearIdCarImage - Registration pages pass idImages.front and idImages.back to API - Field names mapped to PascalCase for .NET API (FullName, Email, etc.)
This commit is contained in:
@ -160,19 +160,63 @@ export async function getTerms() {
|
||||
* @param {Object} data — { name, email, phoneNumber, whatsAppNumber, password, ownerType }
|
||||
* @returns {Promise<{status, data, ok, message}>}
|
||||
*/
|
||||
export async function addOwner(data) {
|
||||
console.log('[Auth] Registering owner:', data.email);
|
||||
return authFetch('/Owner/Add', data);
|
||||
// Multipart form-data fetch for file uploads
|
||||
async function multipartAuthFetch(endpoint, formData) {
|
||||
console.log('[Auth] Multipart request:', `${API_BASE}${endpoint}`);
|
||||
|
||||
const res = await fetch(`${API_BASE}${endpoint}`, {
|
||||
method: 'POST',
|
||||
// Don't set Content-Type — browser sets it with boundary
|
||||
body: formData,
|
||||
});
|
||||
|
||||
console.log('[Auth] Response status:', res.status, endpoint);
|
||||
|
||||
const text = await res.text();
|
||||
let data = null;
|
||||
try {
|
||||
data = text ? JSON.parse(text) : null;
|
||||
if (data && typeof data === 'object' && 'data' in data) {
|
||||
data = data.data;
|
||||
}
|
||||
} catch {
|
||||
data = text;
|
||||
}
|
||||
|
||||
return { status: res.status, data, ok: res.ok || res.status === 206, message: data?.message };
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new customer/tenant
|
||||
* @param {Object} data — { name, email, phoneNumber, password, customerType }
|
||||
* @returns {Promise<{status, data, ok, message}>}
|
||||
*/
|
||||
export async function addCustomer(data) {
|
||||
console.log('[Auth] Registering customer:', data.email);
|
||||
return authFetch('/Customer/Add', data);
|
||||
export async function addOwner(data, frontImage = null, backImage = null) {
|
||||
console.log('[Auth] Registering owner (multipart):', data.email);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('FullName', data.name || data.FullName || '');
|
||||
formData.append('Email', data.email || '');
|
||||
formData.append('PhoneNumber', data.phoneNumber || '');
|
||||
formData.append('WhatsAppNumber', data.whatsAppNumber || '');
|
||||
formData.append('Password', data.password || '');
|
||||
formData.append('Type', String(data.ownerType ?? data.Type ?? 0));
|
||||
|
||||
if (frontImage) formData.append('FrontIdCarImage', frontImage);
|
||||
if (backImage) formData.append('RearIdCarImage', backImage);
|
||||
|
||||
return multipartAuthFetch('/Owner/Add', formData);
|
||||
}
|
||||
|
||||
export async function addCustomer(data, frontImage = null, backImage = null) {
|
||||
console.log('[Auth] Registering customer (multipart):', data.email);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('FullName', data.name || data.FullName || '');
|
||||
formData.append('Email', data.email || '');
|
||||
formData.append('PhoneNumber', data.phoneNumber || '');
|
||||
formData.append('Password', data.password || '');
|
||||
formData.append('Type', String(data.customerType ?? data.Type ?? 0));
|
||||
|
||||
if (frontImage) formData.append('FrontIdCarImage', frontImage);
|
||||
if (backImage) formData.append('RearIdCarImage', backImage);
|
||||
|
||||
return multipartAuthFetch('/Customer/Add', formData);
|
||||
}
|
||||
|
||||
// ─── Auth: Login ───
|
||||
|
||||
Reference in New Issue
Block a user