REFACTOR - Database logic
This commit is contained in:
77
debug_registration.js
Normal file
77
debug_registration.js
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env node
|
||||
const http = require('http');
|
||||
const { URL } = require('url');
|
||||
|
||||
async function testRegistration() {
|
||||
const registerData = {
|
||||
email: `debug.${Date.now()}@bakery.com`,
|
||||
password: 'TestPassword123!',
|
||||
full_name: 'Debug Test User',
|
||||
role: 'admin'
|
||||
};
|
||||
|
||||
const bodyString = JSON.stringify(registerData);
|
||||
console.log('Request body:', bodyString);
|
||||
console.log('Content-Length:', Buffer.byteLength(bodyString, 'utf8'));
|
||||
|
||||
const url = new URL('/api/v1/auth/register', 'http://localhost:8000');
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'User-Agent': 'Frontend-Debug/1.0',
|
||||
'Content-Length': Buffer.byteLength(bodyString, 'utf8')
|
||||
},
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('Making request to:', url.href);
|
||||
console.log('Headers:', options.headers);
|
||||
|
||||
const req = http.request(url, options, (res) => {
|
||||
console.log('Response status:', res.statusCode);
|
||||
console.log('Response headers:', res.headers);
|
||||
|
||||
let data = '';
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
console.log('Response body:', data);
|
||||
|
||||
try {
|
||||
const parsedData = data ? JSON.parse(data) : {};
|
||||
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
resolve(parsedData);
|
||||
} else {
|
||||
reject(new Error(`HTTP ${res.statusCode}: ${JSON.stringify(parsedData)}`));
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('JSON parse error:', e.message);
|
||||
reject(new Error(`HTTP ${res.statusCode}: ${data}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
console.log('Request error:', error);
|
||||
reject(error);
|
||||
});
|
||||
|
||||
console.log('Writing body:', bodyString);
|
||||
req.write(bodyString);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
testRegistration()
|
||||
.then(result => {
|
||||
console.log('✅ Success:', result);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('❌ Error:', error.message);
|
||||
});
|
||||
Reference in New Issue
Block a user