gazill 2.6.1 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAuCA,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAiGlD"}
|
package/dist/commands/login.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import inquirer from 'inquirer';
|
|
2
1
|
import chalk from 'chalk';
|
|
3
2
|
import ora from 'ora';
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { saveAuth, isAuthenticated, getAuth, getApiUrl } from '../lib/config.js';
|
|
4
|
+
// Open URL in default browser
|
|
5
|
+
async function openBrowser(url) {
|
|
6
|
+
const { exec } = await import('child_process');
|
|
7
|
+
const { platform } = await import('os');
|
|
8
|
+
const command = platform() === 'darwin'
|
|
9
|
+
? `open "${url}"`
|
|
10
|
+
: platform() === 'win32'
|
|
11
|
+
? `start "" "${url}"`
|
|
12
|
+
: `xdg-open "${url}"`;
|
|
13
|
+
exec(command, (error) => {
|
|
14
|
+
if (error) {
|
|
15
|
+
console.log(chalk.gray(`Could not open browser. Please visit: ${url}`));
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
6
19
|
export async function loginCommand() {
|
|
7
20
|
// Check if already authenticated
|
|
8
21
|
if (await isAuthenticated()) {
|
|
@@ -11,62 +24,74 @@ export async function loginCommand() {
|
|
|
11
24
|
console.log(chalk.gray('Run "gazill logout" to switch accounts.'));
|
|
12
25
|
return;
|
|
13
26
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type: 'list',
|
|
18
|
-
name: 'action',
|
|
19
|
-
message: 'What would you like to do?',
|
|
20
|
-
choices: [
|
|
21
|
-
{ name: 'Sign in to existing account', value: 'signin' },
|
|
22
|
-
{ name: 'Create a new account', value: 'signup' },
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
]);
|
|
26
|
-
// Get credentials
|
|
27
|
-
const { email, password } = await inquirer.prompt([
|
|
28
|
-
{
|
|
29
|
-
type: 'input',
|
|
30
|
-
name: 'email',
|
|
31
|
-
message: 'Email:',
|
|
32
|
-
validate: (input) => {
|
|
33
|
-
if (!input || !input.includes('@')) {
|
|
34
|
-
return 'Please enter a valid email address';
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
type: 'password',
|
|
41
|
-
name: 'password',
|
|
42
|
-
message: 'Password:',
|
|
43
|
-
mask: '*',
|
|
44
|
-
validate: (input) => {
|
|
45
|
-
if (!input || input.length < 8) {
|
|
46
|
-
return 'Password must be at least 8 characters';
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
]);
|
|
52
|
-
const spinner = ora(action === 'signup' ? 'Creating account...' : 'Signing in...').start();
|
|
27
|
+
const apiUrl = await getApiUrl();
|
|
28
|
+
// Start device auth flow
|
|
29
|
+
const spinner = ora('Starting login...').start();
|
|
53
30
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
:
|
|
57
|
-
|
|
58
|
-
await saveAuth({
|
|
59
|
-
token: response.token,
|
|
60
|
-
email: response.user.email,
|
|
31
|
+
// Get device code
|
|
32
|
+
const startResponse = await fetch(`${apiUrl}/api/auth/device/start`, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'Content-Type': 'application/json' },
|
|
61
35
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
36
|
+
if (!startResponse.ok) {
|
|
37
|
+
throw new Error('Failed to start login flow');
|
|
38
|
+
}
|
|
39
|
+
const { deviceCode, userCode, verificationUrl } = await startResponse.json();
|
|
40
|
+
spinner.stop();
|
|
41
|
+
// Display code and instructions
|
|
42
|
+
console.log('');
|
|
43
|
+
console.log(chalk.blue(' Login to Gazill'));
|
|
44
|
+
console.log('');
|
|
45
|
+
console.log(' Open this URL in your browser:');
|
|
46
|
+
console.log('');
|
|
47
|
+
console.log(chalk.cyan(` ${verificationUrl}`));
|
|
48
|
+
console.log('');
|
|
49
|
+
console.log(' And enter this code:');
|
|
50
|
+
console.log('');
|
|
51
|
+
console.log(chalk.bold.white(` ${userCode}`));
|
|
52
|
+
console.log('');
|
|
53
|
+
// Try to open browser
|
|
54
|
+
await openBrowser(`${verificationUrl}?code=${userCode.replace('-', '')}`);
|
|
55
|
+
// Start polling
|
|
56
|
+
const pollSpinner = ora('Waiting for authorization...').start();
|
|
57
|
+
const pollInterval = 2000; // 2 seconds
|
|
58
|
+
const maxAttempts = 300; // 10 minutes max (300 * 2s)
|
|
59
|
+
let attempts = 0;
|
|
60
|
+
while (attempts < maxAttempts) {
|
|
61
|
+
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
|
62
|
+
const pollResponse = await fetch(`${apiUrl}/api/auth/device/poll`, {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: { 'Content-Type': 'application/json' },
|
|
65
|
+
body: JSON.stringify({ deviceCode }),
|
|
66
|
+
});
|
|
67
|
+
if (!pollResponse.ok) {
|
|
68
|
+
attempts++;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const pollResult = await pollResponse.json();
|
|
72
|
+
if (pollResult.status === 'authorized' && pollResult.token && pollResult.user) {
|
|
73
|
+
// Save auth token
|
|
74
|
+
await saveAuth({
|
|
75
|
+
token: pollResult.token,
|
|
76
|
+
email: pollResult.user.email,
|
|
77
|
+
});
|
|
78
|
+
pollSpinner.succeed(chalk.green('Logged in successfully!'));
|
|
79
|
+
console.log('');
|
|
80
|
+
console.log(chalk.blue(`Welcome, ${pollResult.user.email}!`));
|
|
81
|
+
console.log(chalk.gray('Run "gazill new <project-name>" to create a project.'));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (pollResult.status === 'expired') {
|
|
85
|
+
pollSpinner.fail(chalk.red('Login expired. Please try again.'));
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
attempts++;
|
|
89
|
+
}
|
|
90
|
+
pollSpinner.fail(chalk.red('Login timed out. Please try again.'));
|
|
91
|
+
process.exit(1);
|
|
67
92
|
}
|
|
68
93
|
catch (error) {
|
|
69
|
-
const message = error instanceof Error ? error.message : '
|
|
94
|
+
const message = error instanceof Error ? error.message : 'Login failed';
|
|
70
95
|
spinner.fail(chalk.red(message));
|
|
71
96
|
process.exit(1);
|
|
72
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEjF,8BAA8B;AAC9B,KAAK,UAAU,WAAW,CAAC,GAAW;IACpC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;IAC/C,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;IAExC,MAAM,OAAO,GAAG,QAAQ,EAAE,KAAK,QAAQ;QACrC,CAAC,CAAC,SAAS,GAAG,GAAG;QACjB,CAAC,CAAC,QAAQ,EAAE,KAAK,OAAO;YACtB,CAAC,CAAC,aAAa,GAAG,GAAG;YACrB,CAAC,CAAC,aAAa,GAAG,GAAG,CAAC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