genbox 1.0.136 → 1.0.137
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.
- package/dist/commands/login.js +111 -26
- package/package.json +1 -1
package/dist/commands/login.js
CHANGED
|
@@ -15,42 +15,127 @@ exports.loginCommand = new commander_1.Command('login')
|
|
|
15
15
|
.description('Login to Genbox')
|
|
16
16
|
.action(async () => {
|
|
17
17
|
try {
|
|
18
|
-
|
|
18
|
+
// Step 1: Prompt for email
|
|
19
|
+
const { email } = await inquirer_1.default.prompt([
|
|
19
20
|
{
|
|
20
21
|
type: 'input',
|
|
21
22
|
name: 'email',
|
|
22
23
|
message: 'Email:',
|
|
23
24
|
validate: (input) => input.includes('@') || 'Please enter a valid email',
|
|
24
25
|
},
|
|
25
|
-
{
|
|
26
|
-
type: 'password',
|
|
27
|
-
name: 'password',
|
|
28
|
-
message: 'Password:',
|
|
29
|
-
mask: '*',
|
|
30
|
-
},
|
|
31
26
|
]);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
auth: {
|
|
39
|
-
token: response.access_token,
|
|
40
|
-
user: response.user,
|
|
41
|
-
},
|
|
27
|
+
// Step 2: Send OTP
|
|
28
|
+
console.log(chalk_1.default.dim('Sending verification code...'));
|
|
29
|
+
try {
|
|
30
|
+
await (0, api_1.fetchApi)('/auth/send-otp', {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
body: JSON.stringify({ email }),
|
|
42
33
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.message.includes('rate limit')) {
|
|
37
|
+
console.error(chalk_1.default.red('Too many requests. Please wait a minute and try again.'));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
console.log(chalk_1.default.green('✓ Code sent to your email'));
|
|
43
|
+
console.log('');
|
|
44
|
+
// Step 3: Prompt for OTP with retry logic
|
|
45
|
+
let attempts = 0;
|
|
46
|
+
const maxAttempts = 3;
|
|
47
|
+
let success = false;
|
|
48
|
+
while (attempts < maxAttempts && !success) {
|
|
49
|
+
const { code } = await inquirer_1.default.prompt([
|
|
50
|
+
{
|
|
51
|
+
type: 'input',
|
|
52
|
+
name: 'code',
|
|
53
|
+
message: 'Enter 6-digit code (or type "resend"):',
|
|
54
|
+
validate: (input) => {
|
|
55
|
+
if (input.toLowerCase() === 'resend')
|
|
56
|
+
return true;
|
|
57
|
+
return /^\d{6}$/.test(input) || 'Code must be 6 digits (or type "resend")';
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
// Handle resend
|
|
62
|
+
if (code.toLowerCase() === 'resend') {
|
|
63
|
+
console.log(chalk_1.default.dim('Resending code...'));
|
|
64
|
+
try {
|
|
65
|
+
await (0, api_1.fetchApi)('/auth/send-otp', {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
body: JSON.stringify({ email }),
|
|
68
|
+
});
|
|
69
|
+
console.log(chalk_1.default.green('✓ New code sent'));
|
|
70
|
+
console.log('');
|
|
71
|
+
continue; // Don't count as attempt
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error.message.includes('rate limit')) {
|
|
75
|
+
console.error(chalk_1.default.yellow('Please wait before requesting a new code'));
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Step 4: Verify OTP
|
|
82
|
+
try {
|
|
83
|
+
const response = await (0, api_1.fetchApi)('/auth/verify-otp', {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
body: JSON.stringify({ email, code }),
|
|
86
|
+
});
|
|
87
|
+
if (response && response.access_token) {
|
|
88
|
+
config_store_1.ConfigStore.save({
|
|
89
|
+
auth: {
|
|
90
|
+
token: response.access_token,
|
|
91
|
+
user: response.user,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
// Show logo on successful login
|
|
95
|
+
(0, logo_1.printLogo)(chalk_1.default.green);
|
|
96
|
+
console.log(chalk_1.default.green('✓ Successfully logged in!'));
|
|
97
|
+
// Show completion hint if not already installed
|
|
98
|
+
if (!(0, completion_1.isCompletionInstalledForCurrentShell)()) {
|
|
99
|
+
console.log('');
|
|
100
|
+
console.log((0, completion_1.getCompletionHint)());
|
|
101
|
+
}
|
|
102
|
+
success = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
attempts++;
|
|
107
|
+
if (error.message.includes('expired')) {
|
|
108
|
+
console.error(chalk_1.default.red('Code has expired. Requesting new code...'));
|
|
109
|
+
await (0, api_1.fetchApi)('/auth/send-otp', {
|
|
110
|
+
method: 'POST',
|
|
111
|
+
body: JSON.stringify({ email }),
|
|
112
|
+
});
|
|
113
|
+
console.log(chalk_1.default.green('✓ New code sent'));
|
|
114
|
+
attempts = 0; // Reset attempts for new code
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (error.message.includes('attempts')) {
|
|
118
|
+
console.error(chalk_1.default.red('Too many failed attempts. Requesting new code...'));
|
|
119
|
+
await (0, api_1.fetchApi)('/auth/send-otp', {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
body: JSON.stringify({ email }),
|
|
122
|
+
});
|
|
123
|
+
console.log(chalk_1.default.green('✓ New code sent'));
|
|
124
|
+
attempts = 0; // Reset attempts for new code
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const remaining = maxAttempts - attempts;
|
|
128
|
+
if (remaining > 0) {
|
|
129
|
+
console.error(chalk_1.default.red(`Invalid code. ${remaining} attempt(s) remaining.`));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
console.error(chalk_1.default.red('Too many invalid attempts. Please try again later.'));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
50
135
|
}
|
|
51
136
|
}
|
|
52
|
-
|
|
53
|
-
console.error(chalk_1.default.red('Login failed
|
|
137
|
+
if (!success) {
|
|
138
|
+
console.error(chalk_1.default.red('Login failed. Please try again.'));
|
|
54
139
|
}
|
|
55
140
|
}
|
|
56
141
|
catch (error) {
|