File size: 2,391 Bytes
dd750b7
 
 
 
 
 
 
 
 
 
 
eae7030
dd750b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node

/**
 * 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);