@proagentstore/cli 0.3.1 → 0.3.2
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/index.js +13 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -379,7 +379,6 @@ import { Command as Command3 } from "commander";
|
|
|
379
379
|
var CONFIG_DIR = join3(homedir(), ".config", "proagentstore");
|
|
380
380
|
var TOKEN_FILE = join3(CONFIG_DIR, "session.json");
|
|
381
381
|
var API_BASE = "https://api.proagentstore.online";
|
|
382
|
-
var FAS_API = "https://api.freeappstore.online";
|
|
383
382
|
function loadSession() {
|
|
384
383
|
try {
|
|
385
384
|
if (!existsSync3(TOKEN_FILE)) return null;
|
|
@@ -422,34 +421,32 @@ var loginCommand = new Command3("login").description("Sign in with Google or Git
|
|
|
422
421
|
res.end();
|
|
423
422
|
return;
|
|
424
423
|
}
|
|
425
|
-
const
|
|
426
|
-
if (!
|
|
424
|
+
const session = url.searchParams.get("session");
|
|
425
|
+
if (!session) {
|
|
427
426
|
res.writeHead(400, { "Content-Type": "text/html" });
|
|
428
427
|
res.end("<h1>Sign-in failed</h1><p>No session received.</p>");
|
|
429
428
|
clearTimeout(timeout);
|
|
430
429
|
server.close();
|
|
431
|
-
reject(new Error("No
|
|
430
|
+
reject(new Error("No session in callback"));
|
|
432
431
|
return;
|
|
433
432
|
}
|
|
434
433
|
try {
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
headers: { "Content-Type": "application/json" },
|
|
438
|
-
body: JSON.stringify({ fas_session: fasSession })
|
|
434
|
+
const meRes = await fetch(`${API_BASE}/v1/auth/me`, {
|
|
435
|
+
headers: { Authorization: `Bearer ${session}` }
|
|
439
436
|
});
|
|
440
|
-
|
|
441
|
-
|
|
437
|
+
if (!meRes.ok) throw new Error("Session validation failed");
|
|
438
|
+
const me = await meRes.json();
|
|
442
439
|
saveSession({
|
|
443
|
-
token:
|
|
444
|
-
user:
|
|
440
|
+
token: session,
|
|
441
|
+
user: { id: me.id, login: me.login, avatar: me.avatar },
|
|
445
442
|
expiresAt: Date.now() + 29 * 24 * 60 * 60 * 1e3
|
|
446
443
|
// ~29 days
|
|
447
444
|
});
|
|
448
445
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
449
|
-
res.end(`<h1>Signed in as ${
|
|
446
|
+
res.end(`<h1>Signed in as ${me.login}</h1><p>You can close this tab and return to the terminal.</p><script>window.close()</script>`);
|
|
450
447
|
clearTimeout(timeout);
|
|
451
448
|
server.close();
|
|
452
|
-
resolve5(
|
|
449
|
+
resolve5(session);
|
|
453
450
|
} catch (err) {
|
|
454
451
|
res.writeHead(500, { "Content-Type": "text/html" });
|
|
455
452
|
res.end(`<h1>Sign-in failed</h1><p>${err instanceof Error ? err.message : String(err)}</p>`);
|
|
@@ -460,8 +457,8 @@ var loginCommand = new Command3("login").description("Sign in with Google or Git
|
|
|
460
457
|
});
|
|
461
458
|
server.listen(port, "127.0.0.1");
|
|
462
459
|
});
|
|
463
|
-
const oauthBase = provider === "google" ? `${
|
|
464
|
-
const oauthUrl = `${oauthBase}?
|
|
460
|
+
const oauthBase = provider === "google" ? `${API_BASE}/v1/auth/google/start` : `${API_BASE}/v1/auth/github/start`;
|
|
461
|
+
const oauthUrl = `${oauthBase}?return_to=${encodeURIComponent(callbackUrl)}`;
|
|
465
462
|
const open = (await import("child_process")).exec;
|
|
466
463
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
467
464
|
open(`${cmd} "${oauthUrl}"`);
|