Spaces:
Sleeping
Sleeping
| /** | |
| * Register Admin User | |
| * Quick script to register the admin user for testing | |
| */ | |
| const https = require('https'); | |
| const BASE_URL = 'https://kamau1-swiftops-backend.hf.space'; | |
| const ADMIN_EMAIL = 'lewis.kamau421@gmail.com'; | |
| const ADMIN_PASSWORD = 'TestPass123'; | |
| function makeRequest(method, path, data = null) { | |
| return new Promise((resolve, reject) => { | |
| const url = new URL(path, BASE_URL); | |
| const options = { | |
| method, | |
| headers: { 'Content-Type': 'application/json' } | |
| }; | |
| const req = https.request(url, options, (res) => { | |
| let body = ''; | |
| res.on('data', chunk => body += chunk); | |
| res.on('end', () => { | |
| try { | |
| resolve({ status: res.statusCode, data: JSON.parse(body) }); | |
| } catch (e) { | |
| resolve({ status: res.statusCode, data: body }); | |
| } | |
| }); | |
| }); | |
| req.on('error', reject); | |
| if (data) req.write(JSON.stringify(data)); | |
| req.end(); | |
| }); | |
| } | |
| async function registerAdmin() { | |
| console.log('π Registering Admin User...'); | |
| console.log(`Email: ${ADMIN_EMAIL}`); | |
| console.log(`Password: ${ADMIN_PASSWORD}`); | |
| const response = await makeRequest('POST', '/api/v1/auth/register', { | |
| email: ADMIN_EMAIL, | |
| password: ADMIN_PASSWORD, | |
| first_name: 'Lewis', | |
| last_name: 'Kamau', | |
| phone: '+254712345678' | |
| }); | |
| if (response.status === 201 || response.status === 200) { | |
| console.log('β Admin registered successfully!'); | |
| console.log(`User ID: ${response.data.user.id}`); | |
| console.log(`Token: ${response.data.access_token.substring(0, 30)}...`); | |
| } else if (response.status === 400 && response.data.detail?.includes('already registered')) { | |
| console.log('β οΈ User already exists - trying to login...'); | |
| const loginResponse = await makeRequest('POST', '/api/v1/auth/login', { | |
| email: ADMIN_EMAIL, | |
| password: ADMIN_PASSWORD | |
| }); | |
| if (loginResponse.status === 200) { | |
| console.log('β Login successful!'); | |
| console.log(`User ID: ${loginResponse.data.user.id}`); | |
| } else { | |
| console.log('β Login failed - password might be different'); | |
| console.log('Try resetting the password or use a different email'); | |
| } | |
| } else { | |
| console.log('β Registration failed:', response.status); | |
| console.log(JSON.stringify(response.data, null, 2)); | |
| } | |
| } | |
| registerAdmin().catch(console.error); | |