@@ -5,7 +5,7 @@ const { sdkForConsole, questionGetEndpoint } = require("../sdks");
5
5
const { globalConfig, localConfig } = require("../config");
6
6
const { actionRunner, success, parseBool, commandDescriptions, error, parse, log, drawTable } = require("../parser");
7
7
{% if sdk .test != " true" %}
8
- const { questionsLogin, questionsListFactors, questionsMfaChallenge } = require("../questions");
8
+ const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions");
9
9
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
10
10
const ID = require("../id");
11
11
@@ -165,12 +165,8 @@ login
165
165
166
166
}));
167
167
168
- const logout = new Command("logout")
169
- .description(commandDescriptions['logout'])
170
- .configureHelp({
171
- helpWidth: process.stdout.columns || 80
172
- })
173
- .action(actionRunner(async () => {
168
+ const singleLogout = async (accountId) => {
169
+ try {
174
170
let client = await sdkForConsole();
175
171
176
172
await accountDeleteSession({
@@ -179,8 +175,58 @@ const logout = new Command("logout")
179
175
sdk: client
180
176
})
181
177
182
- globalConfig.setCookie("");
183
- success()
178
+ globalConfig.removeLogin(accountId);
179
+ } catch (e) {
180
+ error('Unable to log out, removing locally saved session information')
181
+ }
182
+ globalConfig.removeLogin(accountId);
183
+ }
184
+
185
+ const logout = new Command("logout")
186
+ .description(commandDescriptions['logout'])
187
+ .configureHelp({
188
+ helpWidth: process.stdout.columns || 80
189
+ })
190
+ .action(actionRunner(async () => {
191
+ const logins = globalConfig.getLogins();
192
+ const current = globalConfig.getCurrentLogin();
193
+
194
+ if (current === '') {
195
+ return;
196
+ }
197
+ if (logins.length === 1) {
198
+ await singleLogout(current);
199
+ success();
200
+
201
+ return;
202
+ }
203
+
204
+ const answers = await inquirer.prompt(questionsLogout);
205
+ const accountIds = [];
206
+
207
+ if (answers.method === 'all') {
208
+ accountIds.push(...logins.map(login => login.id));
209
+ }
210
+
211
+ if (answers.method === 'selected' && answers.accounts) {
212
+ accountIds.push(...answers.accounts);
213
+ }
214
+
215
+ for (let accountId of accountIds) {
216
+ globalConfig.setCurrentLogin(accountId);
217
+ await singleLogout(accountId);
218
+ }
219
+
220
+ const leftLogins = globalConfig.getLogins();
221
+
222
+ if (leftLogins.length > 0 && leftLogins.filter(login => login.id === current).length !== 1) {
223
+ const accountId = leftLogins[0].id;
224
+ globalConfig.setCurrentLogin(accountId);
225
+
226
+ success(`Current account is ${accountId}`);
227
+ }
228
+
229
+ success();
184
230
}));
185
231
{% endif %}
186
232
0 commit comments