@askance/cli 0.2.2 → 0.2.4
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/cli/index.js +34 -11
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -338,7 +338,18 @@ async function setupProject() {
|
|
|
338
338
|
// Fetch existing projects
|
|
339
339
|
const projectsResult = await (0, api_client_1.apiGet)("/api/projects");
|
|
340
340
|
if (!projectsResult.ok || !projectsResult.data) {
|
|
341
|
-
|
|
341
|
+
if (projectsResult.status === 401) {
|
|
342
|
+
console.log(" Session expired. Clearing credentials...");
|
|
343
|
+
const credPath = path_1.default.join(projectDir, ".askance", "credentials");
|
|
344
|
+
if (fs_1.default.existsSync(credPath))
|
|
345
|
+
fs_1.default.unlinkSync(credPath);
|
|
346
|
+
(0, api_client_1.clearConfigCache)();
|
|
347
|
+
console.log(" Please run: npx askance login");
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
console.log(` Could not fetch projects (${projectsResult.error ?? `HTTP ${projectsResult.status}`}).`);
|
|
351
|
+
console.log(" You can link a project later via the dashboard.");
|
|
352
|
+
}
|
|
342
353
|
return;
|
|
343
354
|
}
|
|
344
355
|
const projects = projectsResult.data;
|
|
@@ -440,23 +451,35 @@ async function login() {
|
|
|
440
451
|
}
|
|
441
452
|
catch { }
|
|
442
453
|
}
|
|
443
|
-
//
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
454
|
+
// Verify the token is still valid (hit /api/auth/me)
|
|
455
|
+
const meResult = await (0, api_client_1.apiGet)("/api/auth/me");
|
|
456
|
+
if (!meResult.ok) {
|
|
457
|
+
console.log("\n Session expired. Clearing credentials and starting fresh login...");
|
|
458
|
+
const askanceDir = path_1.default.join(projectDir, ".askance");
|
|
459
|
+
const cPath = path_1.default.join(askanceDir, "credentials");
|
|
460
|
+
if (fs_1.default.existsSync(cPath))
|
|
461
|
+
fs_1.default.unlinkSync(cPath);
|
|
462
|
+
(0, api_client_1.clearConfigCache)();
|
|
463
|
+
// Fall through to the login flow below
|
|
447
464
|
}
|
|
448
465
|
else {
|
|
449
|
-
|
|
466
|
+
// Token is valid — check if a project is linked
|
|
467
|
+
if (!config.projectId) {
|
|
468
|
+
console.log("\n No project linked. Setting up project...");
|
|
469
|
+
await setupProject();
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
console.log(` Project: ${config.projectId}`);
|
|
473
|
+
}
|
|
474
|
+
console.log("\n To log in as a different user, delete .askance/credentials and run login again.");
|
|
475
|
+
return;
|
|
450
476
|
}
|
|
451
|
-
console.log("\n To log in as a different user, delete .askance/credentials and run login again.");
|
|
452
|
-
return;
|
|
453
477
|
}
|
|
454
478
|
// Generate a device code / CLI login token
|
|
455
479
|
console.log("[askance] Logging in to Askance...");
|
|
456
480
|
console.log(` API: ${apiUrl}`);
|
|
457
481
|
// Request a CLI login session from the backend
|
|
458
|
-
const
|
|
459
|
-
const startResult = await apiPost("/api/auth/cli/start");
|
|
482
|
+
const startResult = await (0, api_client_1.apiPost)("/api/auth/cli/start");
|
|
460
483
|
if (!startResult.ok || !startResult.data) {
|
|
461
484
|
console.error("[askance] Failed to start login. Is the API running?");
|
|
462
485
|
console.error(` URL: ${apiUrl}`);
|
|
@@ -486,7 +509,7 @@ async function login() {
|
|
|
486
509
|
const startTime = Date.now();
|
|
487
510
|
while (Date.now() - startTime < maxWait) {
|
|
488
511
|
await new Promise((r) => setTimeout(r, pollInterval));
|
|
489
|
-
const pollResult = await apiGet(`/api/auth/cli/poll/${loginId}`);
|
|
512
|
+
const pollResult = await (0, api_client_1.apiGet)(`/api/auth/cli/poll/${loginId}`);
|
|
490
513
|
if (pollResult.ok && pollResult.data) {
|
|
491
514
|
if (pollResult.data.status === "completed" && pollResult.data.token) {
|
|
492
515
|
// Save credentials
|