Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions templates/cli/lib/commands/generic.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,11 @@ const deleteSession = async (accountId) => {
parseOutput: false,
sdk: client
})

globalConfig.removeSession(accountId);
} catch (e) {
error('Unable to log out, removing locally saved session information')
} finally {
globalConfig.removeSession(accountId);
}
globalConfig.removeSession(accountId);
}

const logout = new Command("logout")
Expand All @@ -195,6 +194,7 @@ const logout = new Command("logout")
}
if (sessions.length === 1) {
await deleteSession(current);
globalConfig.setCurrentSession('');
success("Logging out");

return;
Expand All @@ -216,6 +216,8 @@ const logout = new Command("logout")
globalConfig.setCurrentSession(accountId);

success(`Current account is ${accountId}`);
} else if (remainingSessions.length === 0) {
globalConfig.setCurrentSession('');
}

success("Logging out");
Expand Down
24 changes: 17 additions & 7 deletions templates/cli/lib/config.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,25 @@ class Global extends Config {

getSessions() {
const sessions = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key))
const current = this.getCurrentSession();

return sessions.map((session) => {

return {
id: session,
endpoint: this.data[session][Global.PREFERENCE_ENDPOINT],
email: this.data[session][Global.PREFERENCE_EMAIL]
const sessionMap = new Map();

sessions.forEach((sessionId) => {
const email = this.data[sessionId][Global.PREFERENCE_EMAIL];
const endpoint = this.data[sessionId][Global.PREFERENCE_ENDPOINT];
const key = `${email}|${endpoint}`;

if (sessionId === current || !sessionMap.has(key)) {
sessionMap.set(key, {
id: sessionId,
endpoint: this.data[sessionId][Global.PREFERENCE_ENDPOINT],
email: this.data[sessionId][Global.PREFERENCE_EMAIL]
});
}
})
});

return Array.from(sessionMap.values());
}

addSession(session, data) {
Expand Down
Loading