@glash/cli 0.2.38 → 0.2.39
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/commands/login.mjs +16 -5
- package/package.json +1 -1
package/commands/login.mjs
CHANGED
|
@@ -7,6 +7,17 @@ import { prompt, ok, fail, info, warn, color } from '../lib/ui.mjs';
|
|
|
7
7
|
|
|
8
8
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9
9
|
|
|
10
|
+
async function identityPost(path, body, opts) {
|
|
11
|
+
try {
|
|
12
|
+
return await apiPost(`/identity${path}`, body, opts);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
if (e?.status === 404) {
|
|
15
|
+
return apiPost(`/auth${path}`, body, opts);
|
|
16
|
+
}
|
|
17
|
+
throw e;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
function openBrowser(url) {
|
|
11
22
|
try {
|
|
12
23
|
const opener = platform === 'darwin' ? 'open' : platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
@@ -29,7 +40,7 @@ export async function login({ flags }) {
|
|
|
29
40
|
async function browserLogin(flags) {
|
|
30
41
|
let start;
|
|
31
42
|
try {
|
|
32
|
-
start = await
|
|
43
|
+
start = await identityPost('/cli/device/start', { deviceName: hostname() });
|
|
33
44
|
} catch (e) {
|
|
34
45
|
// Older backend without device auth — fall back to password login.
|
|
35
46
|
warn('Browser login is unavailable; falling back to email/password.');
|
|
@@ -60,7 +71,7 @@ async function browserLogin(flags) {
|
|
|
60
71
|
await sleep(delay);
|
|
61
72
|
let r;
|
|
62
73
|
try {
|
|
63
|
-
r = await
|
|
74
|
+
r = await identityPost('/cli/device/poll', { deviceCode });
|
|
64
75
|
} catch (e) {
|
|
65
76
|
return fail(e.message);
|
|
66
77
|
}
|
|
@@ -84,16 +95,16 @@ async function passwordLogin(flags) {
|
|
|
84
95
|
if (!email || !password) return fail('email and password required');
|
|
85
96
|
|
|
86
97
|
try {
|
|
87
|
-
let r = await
|
|
98
|
+
let r = await identityPost('/login', { email, password });
|
|
88
99
|
|
|
89
100
|
// Second factor is always required. Complete the email-OTP challenge.
|
|
90
101
|
if (!r?.accessToken && r?.secondFactorRequired && !r?.challengeId) {
|
|
91
|
-
r = await
|
|
102
|
+
r = await identityPost('/login', { email, password, secondFactorMethod: 'email_otp' });
|
|
92
103
|
}
|
|
93
104
|
if (!r?.accessToken && (r?.otpRequired || r?.challengeId)) {
|
|
94
105
|
const code = flags.otp || (await prompt('Enter the 6-digit code sent to your email: '));
|
|
95
106
|
if (!code) throw new Error('A verification code is required to sign in.');
|
|
96
|
-
r = await
|
|
107
|
+
r = await identityPost('/login', {
|
|
97
108
|
email,
|
|
98
109
|
password,
|
|
99
110
|
emailOtpCode: String(code).trim(),
|
package/package.json
CHANGED