@kendoo.agentdesk/agentdesk 0.4.4 → 0.4.5
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/cli/login.mjs +49 -3
- package/package.json +1 -1
package/cli/login.mjs
CHANGED
|
@@ -9,6 +9,13 @@ const AGENTDESK_SERVER = process.env.AGENTDESK_SERVER || "https://agentdesk.live
|
|
|
9
9
|
const CONFIG_DIR = join(process.env.HOME || process.env.USERPROFILE, ".agentdesk");
|
|
10
10
|
const CREDENTIALS_PATH = join(CONFIG_DIR, "credentials.json");
|
|
11
11
|
|
|
12
|
+
function getEnvApiKey() {
|
|
13
|
+
const envPath = join(process.cwd(), ".env");
|
|
14
|
+
if (!existsSync(envPath)) return null;
|
|
15
|
+
const match = readFileSync(envPath, "utf-8").match(/AGENTDESK_API_KEY=(.+)/);
|
|
16
|
+
return match?.[1]?.trim() || null;
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
export function getStoredApiKey() {
|
|
13
20
|
if (!existsSync(CREDENTIALS_PATH)) return null;
|
|
14
21
|
try {
|
|
@@ -23,12 +30,51 @@ export async function runLogin() {
|
|
|
23
30
|
console.log(" ━━━━━━━━━━━━━━━━");
|
|
24
31
|
console.log("");
|
|
25
32
|
|
|
26
|
-
// Check if already logged in
|
|
33
|
+
// Check if already logged in — validate key against server
|
|
27
34
|
const existing = getStoredApiKey();
|
|
28
35
|
if (existing) {
|
|
29
|
-
console.log(`
|
|
36
|
+
console.log(` Stored key: ${existing.slice(0, 8)}...`);
|
|
37
|
+
|
|
38
|
+
// Validate against server
|
|
39
|
+
try {
|
|
40
|
+
const res = await fetch(`${AGENTDESK_SERVER}/api/sessions`, {
|
|
41
|
+
headers: { "x-api-key": existing },
|
|
42
|
+
signal: AbortSignal.timeout(5000),
|
|
43
|
+
});
|
|
44
|
+
if (res.ok) {
|
|
45
|
+
console.log(" Status: valid ✓");
|
|
46
|
+
} else {
|
|
47
|
+
console.log(" Status: INVALID — this key is not recognized by the server");
|
|
48
|
+
console.log("");
|
|
49
|
+
console.log(" Run: agentdesk logout && agentdesk login");
|
|
50
|
+
console.log("");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
console.log(" Status: could not reach server (key not validated)");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Warn about .env override and validate it
|
|
58
|
+
const envKey = getEnvApiKey();
|
|
59
|
+
if (envKey && envKey !== existing) {
|
|
60
|
+
console.log("");
|
|
61
|
+
console.log(` ⚠ Warning: .env has a different AGENTDESK_API_KEY (${envKey.slice(0, 8)}...)`);
|
|
62
|
+
console.log(" The .env key takes priority at runtime.");
|
|
63
|
+
try {
|
|
64
|
+
const envRes = await fetch(`${AGENTDESK_SERVER}/api/sessions`, {
|
|
65
|
+
headers: { "x-api-key": envKey },
|
|
66
|
+
signal: AbortSignal.timeout(5000),
|
|
67
|
+
});
|
|
68
|
+
if (envRes.ok) {
|
|
69
|
+
console.log(" .env key status: valid ✓");
|
|
70
|
+
} else {
|
|
71
|
+
console.log(" .env key status: INVALID — update or remove it from .env");
|
|
72
|
+
}
|
|
73
|
+
} catch {}
|
|
74
|
+
}
|
|
75
|
+
|
|
30
76
|
console.log("");
|
|
31
|
-
console.log(" To re-authenticate, run: agentdesk logout");
|
|
77
|
+
console.log(" To re-authenticate, run: agentdesk logout && agentdesk login");
|
|
32
78
|
console.log("");
|
|
33
79
|
return;
|
|
34
80
|
}
|