Skip to content

Commit ea494b7

Browse files
committed
fix(cli): Adapting the client command and bug when getting key.
1 parent c1e5c41 commit ea494b7

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

templates/cli/lib/commands/generic.js.twig

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ const Client = require("../client");
44
const { sdkForConsole, questionGetEndpoint } = require("../sdks");
55
const { globalConfig, localConfig } = require("../config");
66
const { actionRunner, success, parseBool, commandDescriptions, error, parse, log, drawTable } = require("../parser");
7+
const ID = require("../id");
78
{% if sdk.test != "true" %}
89
const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions");
910
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
10-
const ID = require("../id");
1111

1212
const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1';
1313

@@ -259,6 +259,7 @@ const client = new Command("client")
259259

260260
if (endpoint !== undefined) {
261261
try {
262+
const id = ID.unique();
262263
let url = new URL(endpoint);
263264
if (url.protocol !== "http:" && url.protocol !== "https:") {
264265
throw new Error();
@@ -273,7 +274,8 @@ const client = new Command("client")
273274
if (!response.version) {
274275
throw new Error();
275276
}
276-
277+
globalConfig.setCurrentLogin(id);
278+
globalConfig.addLogin(id, {});
277279
globalConfig.setEndpoint(endpoint);
278280
} catch (_) {
279281
throw new Error("Invalid endpoint or your Appwrite server is not running as expected.");
@@ -293,11 +295,12 @@ const client = new Command("client")
293295
}
294296

295297
if (reset !== undefined) {
296-
globalConfig.setEndpoint("");
297-
globalConfig.setKey("");
298-
globalConfig.setCookie("");
299-
globalConfig.setSelfSigned("");
300-
localConfig.setProject("", "");
298+
const logins = globalConfig.getLogins();
299+
300+
for (let accountId of logins.map(login => login.id)) {
301+
globalConfig.setCurrentLogin(accountId);
302+
await singleLogout(accountId);
303+
}
301304
}
302305

303306
success()

templates/cli/lib/config.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ class Global extends Config {
460460
if (!this.hasFrom(Global.PREFERENCE_KEY)) {
461461
return "";
462462
}
463-
return this.get(Global.PREFERENCE_KEY);
463+
return this.getFrom(Global.PREFERENCE_KEY);
464464
}
465465

466466
setKey(key) {

0 commit comments

Comments
 (0)