UNPKG

coolify-deployment-cli

Version:
60 lines (48 loc) 1.92 kB
#!/usr/bin/env node class AuthManager { constructor(httpClient, config) { this.http = httpClient; this.config = config; } async login() { console.log('🔐 Logging into Coolify...'); const loginResponse = await this.http.request(this.config.baseUrl, { headers: { 'Accept': 'text/html' } }); let csrfToken = this.http.csrfToken; console.log(`🔍 CSRF token from cookies: ${csrfToken ? csrfToken.substring(0, 10) + '...' : 'none'}`); if (!csrfToken) { const csrfMatch = loginResponse.data.match(/name="_token" value="([^"]+)"/); if (csrfMatch) { csrfToken = csrfMatch[1]; console.log(`🔍 CSRF token from HTML: ${csrfToken.substring(0, 10) + '...'}`); } } if (!csrfToken) throw new Error('Could not find CSRF token'); console.log('✅ Got CSRF token'); const formData = new URLSearchParams({ email: this.config.email, password: this.config.password, _token: csrfToken }); console.log('🔑 Sending login request...'); const postResponse = await this.http.request(this.config.baseUrl + '/login', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Referer': this.config.baseUrl }, body: formData.toString() }); console.log(`📊 Login response status: ${postResponse.statusCode}`); console.log(`📊 Login response headers: ${JSON.stringify(postResponse.headers, null, 2).substring(0, 200)}...`); if (postResponse.statusCode === 302 || postResponse.statusCode === 200) { console.log('✅ Logged in successfully'); return true; } console.log(`❌ Login failed with status ${postResponse.statusCode}`); console.log(`Response preview: ${postResponse.data.substring(0, 300)}...`); throw new Error('Login failed'); } } module.exports = { AuthManager };