pleumrouter 0.5.17 → 0.5.18
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/package.json +1 -1
- package/src/login.mjs +25 -12
package/package.json
CHANGED
package/src/login.mjs
CHANGED
|
@@ -17,11 +17,17 @@ export function browserCommand(url, platform = process.platform) {
|
|
|
17
17
|
|
|
18
18
|
function openBrowser(url) {
|
|
19
19
|
const { command, args } = browserCommand(url);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
try {
|
|
21
|
+
const child = spawn(command, args, {
|
|
22
|
+
stdio: "ignore",
|
|
23
|
+
detached: true,
|
|
24
|
+
shell: false,
|
|
25
|
+
});
|
|
26
|
+
child.on("error", () => {});
|
|
27
|
+
child.unref();
|
|
28
|
+
} catch {
|
|
29
|
+
// Ignore synchronous spawn failure on headless environments
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
function saveTokens({ access_token, refresh_token, expires_in }) {
|
|
@@ -123,14 +129,21 @@ export async function loginDevice() {
|
|
|
123
129
|
` ${t("Log in at the URL above, then enter the code (within {min} min).", { min: expires_in / 60 })}\n`
|
|
124
130
|
);
|
|
125
131
|
|
|
126
|
-
const
|
|
132
|
+
const expiresIn = Number(expires_in) || 600;
|
|
133
|
+
const pollInterval = Math.max(1, Number(interval) || 5);
|
|
134
|
+
const deadline = Date.now() + expiresIn * 1000;
|
|
127
135
|
while (Date.now() < deadline) {
|
|
128
|
-
await new Promise((r) => setTimeout(r,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
await new Promise((r) => setTimeout(r, pollInterval * 1000));
|
|
137
|
+
let poll;
|
|
138
|
+
try {
|
|
139
|
+
poll = await fetch(`${V1}/auth/device/token`, {
|
|
140
|
+
method: "POST",
|
|
141
|
+
headers: { "Content-Type": "application/json" },
|
|
142
|
+
body: JSON.stringify({ device_code }),
|
|
143
|
+
});
|
|
144
|
+
} catch {
|
|
145
|
+
continue; // Transient network error; retry on next poll tick
|
|
146
|
+
}
|
|
134
147
|
if (poll.status === 202) continue; // authorization_pending
|
|
135
148
|
if (!poll.ok) {
|
|
136
149
|
const e = await poll.json().catch(() => ({}));
|